Android clears / completes previous actions except one

In android, I have the following path:

Step 1 → Step 2 → Step 3 → ... Step N → click ...

When the button is pressed, I want to clear / finish ALL the actions from Activity 2 to N, and then go to Acitivy X. In other words, I want to finish all the actions before the first, and then go to another.

If I use flags:

CLEAR_TOP, CLEAR_TASK, NEW_TASK, etc.

theoretically, this would complete ALL previous actions with the original. Is there a way to save my initial life and move on to X activity?

+4
source share
2 answers

actitvity finish(),

finish();
Intent mIntent = new Intent(Create_Your_Pizza.this, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);;

mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mIntent);
+1

, . , FLAG_ACTIVITY_CLEAR_TOP.

, , , ( ) .

, , : A, B, C, D. D startActivity() , B, C D B , : A, B.

, , . , <

1 → 2 → 3 → ... N → ...

Activity2.class FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP Activity2 ( ) onNewIntent(). , , ActivityX.

, - .:)

0

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


All Articles