Solved

closing a parent activity from within a child activity

Posted on 2014-11-04
1
968 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.

807 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