问题描述
我有一个非常分层的应用程序(活动类似于联赛 > 球队 > 位置 > 球员),因此我将每个活动设置为 singleTop
以保持导航合理并防止重复实例.
I have an app that is very hierarchical (activities are similar to League > Team > Position > Player) and so I've made each activity singleTop
in order to keep navigation sensible and to prevent duplicate instances.
现在我正在制作我的第二个应用程序,我看到它建议将我的应用程序声明为 singleTask
以防止重复实例.有人可以帮助解释每种方法的优点吗?
Now I'm making my second app and I've seen it suggested to declare my application to be singleTask
to prevent duplicate instances. Could someone help explain the advantages of each approach?
我的新应用程序只是一个包含 3 个片段的活动,然后我可能会添加一个设置活动和一个常见问题解答.
My new app is just an activity with 3 fragments and then I'll probably add a settings activity and maybe a FAQ.
我刚刚意识到 singleTask
并没有像我想的那样阻止我的应用程序的重复实例.现在正在寻找处理这个问题的正确方法......
I just realized that singleTask
is NOT preventing duplicate instances of my app, as I had thought. Now looking for the right way to handle this...
推荐答案
我觉得你对 singleTop 和 singleTask 的定义有点偏离.SingleTop 可能会产生重复的实例.让我们以您的示例为例,联赛 > 球队 > 位置 > 球员.如果玩家屏幕中有一个按钮可以将您带到联赛屏幕,它会变成联赛 > 球队 > 位置 > 球员 > 联赛.
I think your definition of singleTop and singleTask is a little off. SingleTop could produce a duplicate instance. Lets use your example, League > Team > Position > Player. If there is a button in the player screen that will take you to the league screen, it will become League > Team > Position > Player > League.
而 singleTask 保证只能存在一个 Activity 实例.
Whereas singleTask guarantees that only one instance of the activity can exist.
这篇关于设置launchMode=“singleTask"vs 设置活动launchMode=“singleTop"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!