Android insert on activity stack

Here's the question: Let them say that the activity stack consists of A-> B-> C.

If the user has completed the order, for example: Start A → B → C, pressing the return button will call C-> B-> A. However, if the user directly enters C (for example: via notification), pressing the "Back" button will close applications instead of going to B-> A.

How to insert an element into the activity stack so that it becomes A-> B-> C, so when the user is pushed back to C, he will always return to B.

thanks

+6
source share
1 answer

just override the onBackPressed () method and startactivity B in activityc and startactivity a in action b.

in action c have the following code:

public void onBackPressed(){ startActivity(new Intent(this,ActivityB.class)); finish(); } 

and in step b this code:

 public void onBackPressed(){ startActivity(new Intent(this,ActivityA.class)); finish(); } 

and in action a have the following code:

 public void onBackPressed(){ finish(); } 
+1
source

Source: https://habr.com/ru/post/913253/


All Articles