Android activity生命周期
Android程序中最基本的就是activity,基本上每一个页面就是一个activity。这里简要阐述activity 的生命周期。
一、activity的状态:
Active
in the stack top of activity,hot-spot owner
在当前活动栈的最上方。
Paused
if “active” acitivity is transparenent or other activity is visiable,now these activity is “paused”,which connot accept inputs.
当前activity不可见,比如说弹出一个对话框阴影遮住该页面。
Stopped
otherwise,if an activity is invisible,now it is “stopped”,but its memory is still there.
跳转到其他页面,不过栈中还保留其页面。
Inactive
when an activity is removed from activity stack,now its is “inactive”,and the memory is released.
该activity从栈中去除
二、activity的生命周期
三、示例代码:
package com.example.androidtest1;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class IntentActivity extends Activity {
private static String tag="test";
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
Log.i(tag, "destroy");
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
Log.i(tag, "pause");
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
Log.i(tag, "resume");
super.onResume();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
Log.i(tag, "restart");
super.onRestart();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
Log.i(tag, "start");
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
Log.i(tag, "stop");
super.onStop();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(tag, "create");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
}
}