关键代码如下:
public class MainActivity extends Activity {
private String msg="Android: ";
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
/**
* Called when the activity is about to become visible.
*/
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(msg, "The onStart() event");
}
/**
* Called when the activity has become visible.
*/
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.d(msg, "The onResume() event");
}
/**
* Called when another activity is taking focus.
*/
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d(msg, "The onPause() event");
}
/**
* Called when the activity is no longer visible.
*/
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(msg, "The onStop() event");
}
/**
* Called just before the activity is destroyed.
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}
运行截图:
当Activity第一次打开时:
当启动另一个Activity时:
当关闭当前的Activity,返回到先前的Activity时:
当销毁当前Activity时: