从系统启动器启动应用程序和自定义应用程序有什么区别?
What's the different between start app from system launcher and custom application?
应用程序 A 有一个主要 activity 启动模式设置为标准,打开它。
当我从系统启动器重新打开它时,一切看起来都很正常。
但是如果通过另一个app B启动app A,A会重启!为什么?
我的代码:
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);
根据https://developer.android.com/guide/topics/manifest/activity-element.html#lmode
,activity的默认android:launchMode
是Standard
来自上面的 link :
Every time there's a new intent for a "standard" activity, a new
instance of the class is created to respond to that intent
所以 onCreate() 将在您启动 intent 时被调用
这是为您的应用程序准备的,对于 Android 启动器它是不同的,它使用 Tasks
即
a collection of activities that users interact with when performing a
certain job
此处定义https://developer.android.com/guide/components/tasks-and-back-stack.html
这些任务保留了堆栈中活动的顺序,因此它知道先恢复哪个。
此引文回答了您关于 Android 设备主屏幕的问题:
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.
应用程序 A 有一个主要 activity 启动模式设置为标准,打开它。 当我从系统启动器重新打开它时,一切看起来都很正常。 但是如果通过另一个app B启动app A,A会重启!为什么?
我的代码:
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);
根据https://developer.android.com/guide/topics/manifest/activity-element.html#lmode
,activity的默认android:launchMode
是Standard
来自上面的 link :
Every time there's a new intent for a "standard" activity, a new instance of the class is created to respond to that intent
所以 onCreate() 将在您启动 intent 时被调用
这是为您的应用程序准备的,对于 Android 启动器它是不同的,它使用 Tasks
即
a collection of activities that users interact with when performing a certain job
此处定义https://developer.android.com/guide/components/tasks-and-back-stack.html
这些任务保留了堆栈中活动的顺序,因此它知道先恢复哪个。
此引文回答了您关于 Android 设备主屏幕的问题:
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.