Search code examples
javaandroidactivity-stack

Android Navigation issue 3 screens


A is my main screen B is an activity in my flow C is an activity that user is taken to once he clicks on a link in B

I need user to be going like A - >B ->C

Now when I click back button on C I should be taken to A. However, when I click back once I reach A, C pops up.

I know it still exists in memory and I have tried FLAG_ACTIVITY_CLEAR_TOP IT DOES NOT WORK FOR MY CASE.

I want all activities running in background to be destroyed once A's oncreate is called. How do I do that?

A has noHistory true B DOES NOT have noHistory true C has noHistory true


Solution

  • Add android:launchMode="singleTop" in the Manifest of Activity A

    From Activity C use:

    Intent in = new Intent(mContext, A.class);
    in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK );
    startActivity(in);
    finish();
    

    You can find more information here