WEB开发网
开发学院手机开发Android 开发 Android 开基础 Calling into the superclass 阅读

Android 开基础 Calling into the superclass

 2010-07-15 21:17:00 来源:WEB开发网   
核心提示:activity生命周期方法的实现必须首先调用其父类版本,例如:protected void onPause() {super.onPause();. . .}下面的7个方法一起定义了一个activity的完整生命周期,Android 开基础 Calling into the superclass,通过实现下面这些方法

activity生命周期方法的实现必须首先调用其父类版本。例如:

protected void onPause() {

super.onPause();

. . .

}

下面的7个方法一起定义了一个activity的完整生命周期。通过实现下面这些方法,你可以监视3个嵌套的循环:

从第一次调用onCreate()到最后的一次调用onDestroy()的完整周期:。一个activity在onCreate()中做所有的”全局”状态的初始化设置,在onDestroy()中释放所有剩余的资源。

从一个对onStart()的调用到一个相应的对onStop()的调用的可见周期。在这个周期内,用户可以在屏幕上看见该activity,虽然它不一定在前端与用户交互。在这两个方法之间,你可以维持被用来显示activity给用户的资源。例如,你可以在onStart()中注册一个Broadcast Receiver来监视影响UI的变化,并在onStop()方法中将其注销。activity在可见和不可见之间发生变化时,onStart()和 onStop()可以被调用很多次。

从一个对onResume()的调用到对onPause()的调用之间的前端周期。在这期间,activity在屏幕上所有其他的activity之前并且和用户交互。一个activity可以频繁的在resumed和paused状态之间切换——例如,在设备休眠时或者当一个新的activity启动时onPause()被调用,onResume()在一个activity的返回值或者一个新的intent被发送的时候调用。因此,这两个方法中的代码应该是轻量级的。

原文

Calling into the superclass

An implementation of any activity lifecycle method should always first call the superclass version. For example:

protected void onPause() {

super.onPause();

. . .

}

Taken together, these seven methods define the entire lifecycle of an activity. There are three nested loops that you can monitor by implementing them:

The entire lifetime of an activity happens between the first call to onCreate() through to a single final call to onDestroy(). An activity does all its initial setup of “global” state in onCreate(), and releases all remaining resources in onDestroy(). For example, if it has a thread running in the background to download data from the network, it may create that thread in

1 2  下一页

Tags:Android 基础 Calling

编辑录入:coldstar [复制链接] [打 印]
赞助商链接