Android Activity 生命周期 图+代码
首先看一下Android api中所提供的Activity生命周期图(不明白的,可以看完整篇文章,在回头看一下这个图,你会明白的):
Activity其实是继承了ApplicationContext这个类,我们可以重写以下方法,如下代码:
[java]
package com.tutor.activitydemo;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ActivityDemo extends Activity {
private static final String TAG = "ActivityDemo";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.e(TAG, "start onCreate~~~");
}
@Override
protected void onStart() {
super.onStart();
Log.e(TAG, "start onStart~~~");
}
@Override
protected void onRestart() {
super.onRestart();
Log.e(TAG, "start onRestart~~~");
}
@Override
protected void onResume() {
super.onResume();
Log.e(TAG, "start onResume~~~");
}
@Override
protected void onPause() {
super.onPause();
Log.e(TAG, "start onPause~~~");
}
@Override www.zzzyk.com
protected void onStop() {
super.onStop();
Log.e(TAG, "start onStop~~~");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.e(TAG, "start onDestroy~~~");
}
}
作者:hjm4702192
补充:移动开发 , Android ,