Android singleTask 和 singleInstance 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23033550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between singleTask and singleInstance
提问by Mick
I did not find any thread on StackOverflow that answer my question. I have already seen this Android singletop singleinstance and singletaskbut that question is related to his project scenario.
我没有在 StackOverflow 上找到任何可以回答我的问题的线程。我已经看过这个Android singletop singleinstance 和 singletask但那个问题与他的项目场景有关。
What are the differences between singleTask and singleInstance?? I have read the docs but could not understand..
singleTask 和 singleInstance 有什么区别??我已阅读文档但无法理解..
I have read this thread also Android singleTask or singleInstance launch mode?but I could not understand. Sorry
我也读过这个线程Android singleTask 还是 singleInstance 启动模式?但我无法理解。对不起
回答by Snicolas
What is unclear from the docs?
文档中有什么不清楚的地方?
The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.
“singleTask”和“singleInstance”模式也仅在一个方面彼此不同:“singleTask”活动允许其他活动成为其任务的一部分。它始终位于其任务的根部,但可以在该任务中启动其他活动(必须是“标准”和“单顶”活动)。另一方面,“singleInstance”活动不允许其他活动成为其任务的一部分。这是任务中唯一的活动。如果它启动另一个活动,该活动将被分配给不同的任务——就像 FLAG_ACTIVITY_NEW_TASK 在意图中一样。
回答by since k saji
singleTask :- A new task will always be created and a new instance will be pushed to the task as the root. However, if any activity instance exists in any tasks, the system routes the intent to that activity instance through the onNewIntent() method call. In this mode, activity instances can be pushed to the same task. This mode is useful for activities that act as the entry points.
singleTask :- 将始终创建一个新任务,并将一个新实例作为根推送到该任务。但是,如果任何任务中存在任何活动实例,系统将通过 onNewIntent() 方法调用将意图路由到该活动实例。在这种模式下,活动实例可以被推送到同一个任务。此模式对于充当入口点的活动很有用。
singleInstance:- Same as singleTask, except that the no activities instance can be pushed into the same task of the singleInstance's. Accordingly, the activity with launch mode is always in a single activity instance task. This is a very specialized mode and should only be used in applications that are implemented entirely as one activity.
singleInstance:- 与 singleTask 相同,除了 no activity 实例可以推送到 singleInstance 的相同任务中。因此,具有启动模式的活动始终处于单个活动实例任务中。这是一种非常专业的模式,应该只用于完全作为一个活动实现的应用程序中。
回答by Dhiraj Himani
SingleInstance is just like a singleton and also its stack is like final class can't be extended. Its always single in its stack.and always there.
SingleInstance 就像一个单例,它的堆栈就像 final 类不能扩展。它在其堆栈中始终是单个的。并且始终存在。