推荐阅读:
Android 深刻理解Activity生命周期的作用及意义
一、概述
Application源码介绍,如下所示:
/**
* Base class for maintaining global application state. You can provide your own
* implementation by creating a subclass and specifying the fully-qualified name
* of this subclass as the <code>"android:name"</code> attribute in your
* AndroidManifest.xml's <code><application></code> tag. The Application
* class, or your subclass of the Application class, is instantiated before any
* other class when the process for your application/package is created.
*
* <p class="note"><strong>Note: </strong>There is normally no need to subclass
* Application. In most situations, 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), include
* {@link android.content.Context#getApplicationContext() Context.getApplicationContext()}
* as a {@link android.content.Context} argument when invoking your singleton's
* <code>getInstance()</code> method.
* </p>
*/
概述:
Application类是为了那些需要保存全局变量设计的基本类,你可以在AndroidManifest.xml的<application>标签中通过"android:name"属性进行使用,自定义的application作为基类会影响该程序中每个类的建立,只需要调用Context的getApplicationContext或者Activity的getApplication方法来获得一个application对象,就能做出相应的处理。