Why use Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_SINGLE_TOP?

when I push the push notification, I use something like this to trigger the intention that I want:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
ctx.startActivity(intent);

This is part of the code taken from the tutorial, but I really did not understand the use of both FLAG_ACTIVITY_NEW_TASK, and FLAG_ACTIVITY_SINGLE_TOP.

From the docs:

FLAG_ACTIVITY_NEW_TASK (added to API level 1):

When using this flag, if the task is already running for the action you are starting now, then the new activity will not be started; instead, the current task will simply be brought to the forefront of the screen with the state of the latter.

FLAG_ACTIVITY_SINGLE_TOP (added to API level 4):

If set, the action will not be launched if it is already running at the top of the history stack.

, , , NEW_TASK , , , ( , ), SINGLE_TOP , (, )?

: , ?

+5
1

AFAIK

FLAG_ACTIVITY_SINGLE_TOP . ( , , , . , )

FLAG_ACTIVITY_NEW_TASK , .

, , , FLAG_ACTIVITY_SINGLE_TOP FIRST TIME, , FLAG_ACTIVITY_NEW_TASK .

+2

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


All Articles