Remove all application actions from every existing task in Activity Back Stack

Is there a way to remove all actions belonging to the application in the foreground (my application)?

Actions may be present in different tasks. Also, after deleting all the actions, my application should return to the main screen, which is the activity of launching my application.

Any help is appreciated.

+3
source share
3 answers

You need to call your activity as follows.

Intent login=new Intent(MainActivity.this,HomeActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
login.putExtra("flag",false);
startActivity(login);
finish();
+1
source

You may need

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

FLAG_ACTIVITY_CLEAR_TASK

Any existing task that will be associated with the current activity, which will be cleared before the desired activity is launched. Simply old activities are finished.

FLAG_ACTIVITY_NEW_TASK

, become the start of a new task .

Intent Flags

0
    Intent i = new Intent(OldActivity.this, NewActivity.class);
    // set the new task and clear flags
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(i);
finish();
0
source

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


All Articles