If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "static", with zero risk. Yes?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- suppress a singleton constructor in java with powe
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
The Android documentation says -
This means you can use static members.
Besides, a
standard
orsingleTop
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.Yes, an Activity can be a "singleton" if you ensure that an instance of Activity A isn't started while another instance of Activity A is in the activity stack (an instance of Activity A could technically start another instance of itself).
One thing please DO NOT use singleTask or singleInstance for this purpose. The activity launch flags are there to control how activity stacks behave. They have visible impact on the user interaction with your activity (making it non-standard). Those modes are intended to be used when you want that kind of user interaction, they should NOT be used to change the implementation details of your app.
No. The same
Activity
can be started multiple times in the same process. For example, you can try starting anActivity
from itself, when clicking a button.Please see the activity property launchMode at android.developer page.
Quote: "standard is the default mode and is appropriate for most types of activities. SingleTop is also a common and useful launch mode for many types of activities. The other modes — singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications."