android Application类的详细介绍
来源:互联网 发布:2016年8月进出口数据 编辑:程序博客网 时间:2024/04/30 03:22
一.先对它的整体概念解释:
在android源码中对他的描述是;
* 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.
SDK中的描述:Application类是为了那些需要保存全局变量设计的基本类,你可以在AndroidManifest.xml的<application>标签中进行自己的实现,这样的结果是:当你的 application或者包被建立的时候将引起那个类被建立。
理解:就是说application是用来保存全局变量的,并且是在package创建的时候就跟着存在了。所以当我们需要创建全局变量的时候,不需 要再像j2se那样需要创建public权限的static变量,而直接在application中去实现。只需要调用Context的getApplicationContext或者Activity的getApplication方法来获得一个application对象,再做出相应 的处理。
例如Launcher模块中;它自己就写了个application,在AndroidManifest.xml中将它进行了设置:
<application
android:name="com.android.launcher2.LauncherApplication"
对于他的设置可以参考这个模块。
二.里面的方法进行说明:
onCreate();
/**
* Called when the application is starting, before any other application
* objects have been created. Implementations should be as quick as
* possible (for example using lazy initialization of state) since the time
* spent in this function directly impacts the performance of starting the
* first activity, service, or receiver in a process.
* If you override this method, be sure to call super.onCreate().
*/
这个函数是当我们的应用开始之时就被调用了,比应用中的其他对象创建的早,这个实现尽可能的快一点,因为这个时间直接影响到我们第一个activity/service
/receiver。如果你要重写这个方法必须调用super.onCreate().
onTerminate():
/**
* This method is for use in emulated process environments. It will
* never be called on a production Android device, where processes are
* removed by simply killing them; no user code (including this callback)
* is executed when doing so.
*/
这个函数是模拟一个过程环境,在真机中永远也不会被调用。
在android源码中对他的描述是;
* 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.
SDK中的描述:Application类是为了那些需要保存全局变量设计的基本类,你可以在AndroidManifest.xml的<application>标签中进行自己的实现,这样的结果是:当你的 application或者包被建立的时候将引起那个类被建立。
理解:就是说application是用来保存全局变量的,并且是在package创建的时候就跟着存在了。所以当我们需要创建全局变量的时候,不需 要再像j2se那样需要创建public权限的static变量,而直接在application中去实现。只需要调用Context的getApplicationContext或者Activity的getApplication方法来获得一个application对象,再做出相应 的处理。
例如Launcher模块中;它自己就写了个application,在AndroidManifest.xml中将它进行了设置:
<application
android:name="com.android.launcher2.LauncherApplication"
对于他的设置可以参考这个模块。
二.里面的方法进行说明:
onCreate();
/**
* Called when the application is starting, before any other application
* objects have been created. Implementations should be as quick as
* possible (for example using lazy initialization of state) since the time
* spent in this function directly impacts the performance of starting the
* first activity, service, or receiver in a process.
* If you override this method, be sure to call super.onCreate().
*/
这个函数是当我们的应用开始之时就被调用了,比应用中的其他对象创建的早,这个实现尽可能的快一点,因为这个时间直接影响到我们第一个activity/service
/receiver。如果你要重写这个方法必须调用super.onCreate().
onTerminate():
/**
* This method is for use in emulated process environments. It will
* never be called on a production Android device, where processes are
* removed by simply killing them; no user code (including this callback)
* is executed when doing so.
*/
这个函数是模拟一个过程环境,在真机中永远也不会被调用。
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍 .
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- Android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- android Application类的详细介绍
- DDMS简介
- 挫败感
- 如何通过DBLINK取REMOTE DB的DDL
- 《第八周实验报告任务1》
- 一个LINUX学习高手写给初学者的话
- android Application类的详细介绍
- js正则函数match、exec、test、search、replace、split使用介绍集合
- Jakarta Commons NET(FTPClient)的简单示例
- Android环境搭建问题的解决:Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml,
- 在myeclipse中用build.xml布署ejb的问题
- fedora 16字体显示
- Android使用TableLayout动态布局实例
- 一次坏块的处理过程
- VC无闪烁刷屏技术的实现