Home Ask Login Register

Developers Planet

Your answer is one click away!

amit_kumar February 2016

How to finish parent activity without finishing child activity in case of multiple instance of parent and child activities?

I want to make context variable static for an activity which is parent activity A of child activity B. I am following this link http://androiddhina.blogspot.in/2015/02/finish-parent-activity-from-child.html.

Here is the workflow of Activities:

First activity A will be shown then it will go to activity B. I do not want to finish activity A until some task on activity B has finished successfully.

If task is successful then I want activity to go away so that if user presses back button he goes to parent of activity A. There is another button on activity B that launches another activity A.

If the task has failed user can go back to activity A by pressing back button. (I think in this case activity B will automatically be finshed by android).

As per the link I am following, context of Activity A will be static and remain same even if it gets finished for the first time. But I doubt it will work correctly in my case if its not same when ever a new instance of it is created. Does activity's context remain same for multiple instances?enter image description here


JBA February 2016

I would handle the back button into B and adjust the action depending on the current situation:

public void onBackPressed() {
    if (I_CAN_GO_BACK_TO_A) {
    } else {
        //do something else... launch another activity, relaunch A, whatever

Post Status

Asked in February 2016
Viewed 2,828 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life