我可以通过将适当的成员声明为“静态"来获得一些效率吗?在Android活动中 [英] Can I gain some efficiency by declaring appropriate members "static" in Android Activity

查看:43
本文介绍了我可以通过将适当的成员声明为“静态"来获得一些效率吗?在Android活动中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在实践中一个Activity是单身人士,我认为我可以通过将适当的成员声明为静态"且零风险来提高效率.是吗?

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.

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

此外,standardsingleTop应该仅具有线程安全的静态成员.假设当前活动堆栈为A-B-C-D.如果到达意图是针对标准"或单顶"模式下类型B的活动. B的新实例将被启动为(因为B不在堆栈的顶部),因此生成的堆栈将为A-B-C-D-B.

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.

这篇关于我可以通过将适当的成员声明为“静态"来获得一些效率吗?在Android活动中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆