我一直在重读这篇文章,但无法理解它,你能给我解释一下吗?
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/