难道Android的确保的活动是一个单身?是一个、单身、Android

由网友(奋斗第一.)分享简介:如果一个活动是在实践单身,我想我可以通过声明适当的成员静,以零风险获得一定的效益。是的?If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "sta...

如果一个活动是在实践单身,我想我可以通过声明适当的成员静,以零风险获得一定的效益。是的?

If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "static", with zero risk. Yes?

推荐答案

在 Android的文件说, -

从未有多个实例的详细   一个singleTask或singleInstance   活性,使实例预期   处理所有新的意图。

there's never more than one instance of a "singleTask" or "singleInstance" activity, so that instance is expected to handle all new intents.

这意味着您可以使用静态成员

此外,一个标准 singleTop 应具备的线程安全的静态成员只有 。假设当前活动栈为A-B-C-D。如果到达的意图是B型的活性是在标准或singleTop模式。乙的一个新实例将被推出,(因为B不是在堆栈的顶部),因此,所得到的堆叠将是ABCDB。

Besides, a standard or singleTop should have thread-safe static members only. Suppose the current activity stack is A-B-C-D. If the arriving intent is for an activity of type B which is in "standard" or "singleTop" mode. A new instance of B would be launched as (since B is not at the top of the stack), so the resulting stack would be A-B-C-D-B.

阅读全文

相关推荐

最新文章