Solved

closing a parent activity from within a child activity

Posted on 2014-11-04
1
1,007 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Title # Comments Views Activity
moto 4g plus silence 65 144
Android tablet will not connect to internet. 4 41
QQ problem 22 90
Google Factory Reset Protection - Corporate devices 4 56
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

739 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