Jan
Jan

Reputation: 3401

Clearing the Launcher Activity from the stack

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
}

Upvotes: 2

Views: 851

Answers (1)

athingunique
athingunique

Reputation: 151

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

Upvotes: 5

Related Questions