Search code examples
androidandroid-activityparent

Close parent activity and launch a new one


I have a base activity and some child activities like A, B, C and D. Here A is parent of B, C and D means that when either B, C or D finishes, control comes back to A. Now what I want is that when Activity say D finishes, it also close A (parent) and launch a new one say E. Here E should be the only on stack. Its mean close all the activities that are invisible or waiting for result and launch a new one (E).


Solution

  • I don't know if this will work, but you could try it:

    From Activity A, start activity B for a result using startActivityForResult()

    set a result that will inform A to finish as well,

    Call finish() in B.

    When A receives that result from B, A calls finish() on itself as well.

    and there you can start another activity.

    for this you can set the request code for more than one activity which was start as for result and check into onActivityResult() to compare the result code