I guess that the main purpose of the non-UI fragments is the storage of data that is retained over configuration changes, right? So, appart from being this storage specific for the Activity that owns this fragment, which is the benefit of its usage over a Singleton pattern across the entire application (which is the solution I've been doing so far)?
相关问题
- 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 fact that a fragment is scoped to its activity means there is less chance of a long-term memory leak, as opposed to singletons -- the fragment should eventually get garbage-collected, while the singleton will not.
You also have somewhat more control over timing. The
Application
is created just after anyContentProviders
in your app, and you have no choice on that. Conversely, you control when fragments get created, and therefore may be able to take advantage of that control.So, for places where the data is really only needed by an activity, a non-UI fragment is probably a better idea than a singleton. The singleton would be for places where the data is needed across multiple components.