java.lang.Object | |||
↳ | android.content.Context | ||
↳ | android.content.ContextWrapper | ||
↳ | android.app.Application |
Known Direct Subclasses |
Class Overview
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 uses Context.getApplicationContext()
when first constructing the singleton.
翻译:Application类用于保存整个App的状态【全局静态变量】。在main.xml中配置一下,然后系统会实例化Application类。
一般情况都是使用Application的子类。静态单例模式也能起到同样的作用。例如:单例模式需要一个全局变量context,Context.getApplicationContext()
函数能提供context,一般用于构造器。
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
onConfigurationChanged(
Configuration newConfig) --------------------- > 我的组件正在运行的情况下,当设备的配置变化了,Android系统会回调此函数
Called by the system when the device configuration changes while your component is running.
| ||||||||||
void |
onCreate()
--------------------- > App 开始运行的时候被调用,在四大组件被created之前就调用
Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.
| ||||||||||
void |
onLowMemory()
--------------------- > 设备处于低内存状态下调用,正在运行的Activity应该释放一些内存
This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.
| ||||||||||
void |
onTerminate()
--------------------- > 模拟器用
This method is for use in emulated process environments.
| ||||||||||
void |
onTrimMemory(int level)
--------------------- > Android操作系统觉得现在是释放内存的好时机,会调用这个方法,释放内存
Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
| ||||||||||
void | registerActivityLifecycleCallbacks( Application.ActivityLifecycleCallbacks callback) | ||||||||||
void |
registerComponentCallbacks(
ComponentCallbacks callback)
Add a new
ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called.
| ||||||||||
void | registerOnProvideAssistDataListener( Application.OnProvideAssistDataListener callback) | ||||||||||
void | unregisterActivityLifecycleCallbacks( Application.ActivityLifecycleCallbacks callback) | ||||||||||
void |
unregisterComponentCallbacks(
ComponentCallbacks callback)
Remove a
ComponentCallbacks objec that was previously registered with
registerComponentCallbacks(ComponentCallbacks) .
| ||||||||||
void | unregisterOnProvideAssistDataListener( Application.OnProvideAssistDataListener callback) |
其他人的博客: http://blog.csdn.net/lieren666/article/details/7598288#comments
总结:
1、Application的声明周期 == 整个App的生命周期
2、Application 是全局单例,所以可以用来做数据传递,缓存,共享