Solved

closing a parent activity from within a child activity

Posted on 2014-11-04
1
889 Views
Last Modified: 2014-11-20
Hi,
I am starting a new activity from my existing one like this -
Tring.java
 Intent intent = new Intent(tring, NumberActivity.class);
startActivityForResult(intent,1);

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
Log.d("Tring","Inside onActivityResult of Tring");
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                this.finish();

            }
        }
    }



Now in NumberActivity.java i have the following piece of code :
setResult(RESULT_OK, null);
          finish();

According to what i have read this should close out my current Activity (ie. NumberActivity) and call onActivityResult method of Tring.java inside which i have made a call to finish. so the parent activity gets finished.
But this is not happening.

Please help.
thanks
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 6

Accepted Solution

by:
Rafael I earned 500 total points
Comment Utility
one way to approach this is to kill your parent activity when you start the child activity.  that way when you finish with the child activity, you can exit without worrying about the parent activity.  if you need the parent activity, just have the child activity call the parent activity.  then you just have to worry about storing the information of the parent (if any) in order to call it again.

to kill the parent activity after calling the child, override the onPause function and tell it to finish there.  for example:

@Override
protected void onPause() {
    super.onPause();
    finish();
}

Open in new window


good luck!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now