What happens when you click on an app launch icon?
Launch applications call startActivity with the intent [action = Intent.ACTION_MAIN, category = Intent.CATEGORY_LAUNCHER and flag = Intent.FLAG_ACTIVITY_NEW_TASK].
Regarding Intent.FLAG_ACTIVITY_NEW_TASK , from the docs :
When using this flag, if the task is already running for the action that you are currently running, then the new action will not be launched; instead, the current task will simply be displayed on the front of the screen in the state in which it was last.
OnNewIntent Basics:
onNewIntent only delivered when the activity has set singleTask run singleTask and singleInstance . It is also delivered if the action has set singleTop run singleTop or the intention to run the action has set the FLAG_ACTIVITY_SINGLE_TOP flag and the action instance is already at the top of the target. This means that an attempt was made to start a new instance of the action, instead, the existing instance itself must process the intent.
Here is the answer to your inquiries:
Is a new intention always sent, or does the result sometimes coincide with the resumption of a task from recent tasks?
If the task is already running, it is brought to the fore. If the flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET was used to start the action, and then the task FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET in the foreground, the action is terminated. From the docs :
This is useful for cases where you have a logical gap in your application. For example, an email application may have a command for viewing an attachment that starts an image viewing operation to display it. This action must be part of the task of the email application, as it is part of the task in which the user is involved. However, if the user leaves this task and then selects the email application from home, we may like to return to the conversation they were looking at rather than to the attached image, as this is confusing. If you select this check box when starting the image viewer, then this viewer and any actions it launches will be deleted the next time the user returns to the mail.
-
If the intent is sent, when is it sent to the onCreate () method of the new instance of the action and when is it routed through onNewIntent () of the existing action?
onCreate is called when a new instance of the action is created. onNewIntent is called if an action instance already exists and it is not necessary to create a new instance, as in the case of singleInstance , singleTask and conditionally singleTop (as described above).
Suppose an intent is routed through onNewIntent () of an existing action in a task. What kind of activity is he going to? Closest to the top or closest to the root? Will it always be sent to the action instance to launch the application, or can it sometimes be sent to the action with the same binding as the root? Could it ever be sent to an activity that does not have the same proximity as the root?
In the case of singleTask and singleInstance this should be the root of the task. In the case of singleTop this should be a singleTop task task.
Finally, how does all this affect the different launch modes (standard, one top, one instance, one task) of the actions in the task?
I hope that the explanation provided so far answers it.
Update 1:
Here is the Launcher code that adds flags to the intent:
void processShortcut(Intent intent) { .... Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); .... } void startActivitySafely(Intent intent) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ... startActivity(intent); }