Application 翻译

public class

Application

extends  ContextWrapper
implements  ComponentCallbacks2
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 是全局单例,所以可以用来做数据传递,缓存,共享



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值