希望有人能帮我弄清楚,如果不是解决方案,至少是一个行为的解释。
存在的问题:
在某些设备上,按下启动器图标会导致当前任务被恢复,在其他设备上则会导致初始启动意图被触发(有效地重新启动应用程序)。为什么会发生这种情况?
细节:
当你按下“启动器图标”时,应用程序正常启动——也就是说,我假设,一个Intent以你的第一个Activity的名称启动,动作为android.intent.action.MAIN,类别为android.intent.category.LAUNCHER。但情况并非总是如此:
在大多数设备上,如果你在应用程序已经运行后按下启动器图标,该进程中当前运行的Activity将恢复(而不是初始Activity)。它以相同的方式恢复,就像你从操作系统菜单中的“最近任务”中选择它一样。这是我想在所有设备上的行为。
然而,在选定的其他设备上,会发生不同的行为:
On the Motorola Xoom, when you press the launcher icon, the App will always start the initial launch Activity regardless of what is currently running. I assume that the launcher icons always start the "LAUNCHER" intent. On the Samsung Tab 2, when you press the launcher icon, if you have just installed the app, it will always launch the initial Activity (Same as the Xoom) - however, after you restart the device after the install, the launcher icon will instead resume the app. I assume that these devices add "installed apps" into a lookup table on device startup which allow the launcher icons to correctly resume running tasks?
我读过很多答案,听起来类似于我的问题,但简单地添加android:alwaysRetainTaskState="true"或使用launchMode="singleTop"的活动不是答案。
编辑:
在这个应用程序最近一次启动后,我们发现在第一次重启后,这种行为已经开始在所有设备上发生。这对我来说似乎很疯狂,但通过重新启动过程,我实际上找不到哪里出了问题。