What's the different between start app from system launcher and custom application?

1.2k Views Asked by At

App A has an main activity that launch mode set as standard, open it. When I reopen it from system launcher, everything looks normal. But if start app A through another app B, A restart! Why?

My code:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("A's package name");
    launchIntent.setAction(Intent.ACTION_MAIN);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(launchIntent);
1

There are 1 best solutions below

3
On BEST ANSWER

The default android:launchMode of the activity is Standard according to https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

From the link above :

Every time there's a new intent for a "standard" activity, a new instance of the class is created to respond to that intent

So the onCreate() will be called as much time as you start the intent

This was for your app, for Android launcher it is different, it uses Tasks which are

a collection of activities that users interact with when performing a certain job

defined here https://developer.android.com/guide/components/tasks-and-back-stack.html

These tasks conserve the order of the activities in the stack so it knows which one to resume first.

This quotation answers your question about Android Device Home Screen :

The device Home screen is the starting place for most tasks. When the user touches an icon in the application launcher (or a shortcut on the Home screen), that application's task comes to the foreground. If no task exists for the application (the application has not been used recently), then a new task is created and the "main" activity for that application opens as the root activity in the stack.