Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

closing a parent activity from within a child activity

Posted on 2014-11-04
1
Medium Priority
?
1,145 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 1000 total points
ID: 40443726
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
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.

783 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