2

In my app, I have activity A (Launcher/Main Activity) ,B,C. A launches B or C depending on if the user is authenticated.

Now how do I remove A such that when the back button is pressed it just exits the app, not to A. Setting the flag FLAG_ACTIVITY_CLEAR_TOP doesn't seem to work.

@Override
public void onBackPressed{
    super.onBackPressed();
    finish(); // finish activity B or C

    //also finish activity A
}
Jan
  • 3,393
  • 4
  • 21
  • 47

1 Answers1

5

I think you need to set

android:noHistory="true"

on A. You might also need to launch B/C with these Flags:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);    

Finally, you can finish all activities under the current one in the task stack with the same affinity by calling:

finishAffinity()

For further information: Android: Clear the back stack

Community
  • 1
  • 1
athingunique
  • 151
  • 6