android - 你能帮我理解 Android SDK 中的这些信息吗

标签 android

我一直在重读这篇文章,但无法理解它,你能给我解释一下吗?

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.

来自 http://developer.android.com/reference/android/app/Application.html

我不明白为什么不需要子类化应用程序。我经常将它子类化,这样我就可以从任何地方访问应用程序上下文。那么,根据这个文档,正确的方法应该是什么?

最佳答案

我认为这个想法是避免重载 Application 类,而是让多个小型单例类专注于不同的关注点。

这可能就是他们所说的“更模块化的方式”的意思。

关于android - 你能帮我理解 Android SDK 中的这些信息吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509318/

相关文章:

android - 没有适用于 Flutter Android Studio 项目的 AVD

android - 如何使用aapt2,文档在哪里?

java - ListView OnItemClickListener 不适用于 LazyAdapter ListView

java - 通过 id 从嵌套对象序列化

php - Android:进行 HTTP 调用时使用 cookie 保持服务器 session

android - Google App Indexing 页面查看记录是否在本地工作?

android - BottomsheetFragment 内的 Fragment 内的 Recyclerview 不滚动?

android - 一种尺寸适合所有屏幕分辨率

android - 内存不足错误 : bitmap size exceeds VM budget (Android)

android - Gcm Network Manager 周期性任务处理