0

I have a main activity A from where I can launch a second activity B. It's possible to remove Bfrom back stack using a method in A?

Wuagliono
  • 162
  • 1
  • 11
  • try this link : https://stackoverflow.com/questions/39010977/how-to-remove-activity-from-back-stack-in-android – mohammadReza Abiri Oct 12 '19 at 22:20
  • @Wuagliono public void onBackPressed() { Toast.makeText( MainActivity.this, "Can NOT Go Back", Toast.LENGTH_LONG ).show(); } – Vector Oct 12 '19 at 22:22

1 Answers1

1

There might be hacks that would allow such a thing like making B not part of the back stack, but this also means that when you switch away from your app to another and return to it that the user should land on A again, not B.

It would be better to know what exactly you want to achieve as there might be an "official" to do just that. If you, for example, just want that in a chain of A -> B -> A you don't want to navigate back to B after being in the last A state, the answer would be to start A always with the intent flag FLAG_ACTIVITY_CLEAR_TASK, as it would throw away all the history and would start A anew.

Thomas Keller
  • 5,933
  • 6
  • 48
  • 80