应用程序在启动器点击后再次启动,即使它已经 运行
App is getting started again after launcher click even when it is already running
我遇到的问题是,如果用户单击启动器图标,我的应用程序将再次启动,即使它已经是 运行。我使用 singleTaks
作为那个 Activity 并且正如许多 Whosebug 答案所说 -> 这应该可以解决问题 - 但它没有。
<activity
android:name=".activities.ActivitySplash"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如您所见,我确实将 launchMode
定义为 singleTask
。我打开应用程序。导航到屏幕 X(我什至可以留在开始屏幕上,效果相同),现在我按下主页按钮。当我现在再次按下启动器图标时,已经 运行 的应用程序不会弹出或正在恢复(随意调用)。相反,该应用程序已完全启动。
如果 singleTask
不起作用,我该如何防止这种行为?
尝试使用 SingleTop:
if the target task already has an existing instance of the activity
at the top of its stack, that instance will receive the new intent (in
an onNewIntent() call); a new instance is not created. In other
circumstances — for example, if an existing instance of the
"singleTop" activity is in the target task, but not at the top of the
stack, or if it's at the top of a stack, but not in the target task —
a new instance would be created and pushed on the stack.
我遇到的问题是,如果用户单击启动器图标,我的应用程序将再次启动,即使它已经是 运行。我使用 singleTaks
作为那个 Activity 并且正如许多 Whosebug 答案所说 -> 这应该可以解决问题 - 但它没有。
<activity
android:name=".activities.ActivitySplash"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如您所见,我确实将 launchMode
定义为 singleTask
。我打开应用程序。导航到屏幕 X(我什至可以留在开始屏幕上,效果相同),现在我按下主页按钮。当我现在再次按下启动器图标时,已经 运行 的应用程序不会弹出或正在恢复(随意调用)。相反,该应用程序已完全启动。
如果 singleTask
不起作用,我该如何防止这种行为?
尝试使用 SingleTop:
if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.