Android重要概念2—Application类

来源:互联网 发布:墙面网络面板 编辑:程序博客网 时间:2024/05/21 19:43

Application类

 

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created. 

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 usesContext.getApplicationContext() when first constructing the singleton.

 

Context.getApplicationContext()

 

public                           abstract                  ContextgetApplicationContext()

  Since: API Level 1

Return the context of the single, global Application object of the current process.  This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.

 

原创粉丝点击