我有一个静态应用程序快捷方式声明如下:
<shortcut
android:enabled="true"
android:icon="@drawable/shortcut"
android:shortcutDisabledMessage="@string/downloads"
android:shortcutId="downloads"
android:shortcutLongLabel="@string/downloads"
android:shortcutShortLabel="@string/downloads">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.colinrtwhite.test.activity.DownloadsActivity"
android:targetPackage="com.colinrtwhite.test"/>
</shortcut>
Run Code Online (Sandbox Code Playgroud)
它在我的 AndroidManifest.xml 中声明如下:
<activity
android:name=".activity.DownloadsActivity"
android:launchMode="singleTask"
android:theme="@style/AppTheme"/>
Run Code Online (Sandbox Code Playgroud)
根据文档,singleTask启动模式应该重用 Activity 的现有实例并通过 onNewIntent 方法传递新意图。但是,如果我有一个现有的 DownloadsActivity 实例并点击应用程序快捷方式启动它,它将销毁然后重新创建该活动。
我的问题:如何强制应用程序快捷方式重新使用我的 Activity 的现有实例而不是重新启动它?
根据文档,您正在使用静态快捷方式
静态快捷方式不能具有自定义意图标志。静态快捷方式的第一个意图将始终设置 FLAG_ACTIVITY_NEW_TASK 和 FLAG_ACTIVITY_CLEAR_TASK。这意味着,当应用程序已经运行时,当静态快捷方式启动时,所有现有的 Activity 都将被销毁。
同样根据同一部分
可以使用任何一组 Intent 标志发布动态快捷方式。通常,指定 FLAG_ACTIVITY_CLEAR_TASK,可能与其他标志一起;
https://developer.android.com/reference/android/content/pm/ShortcutManager.html,部分快捷方式意图。
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |