首页 > 代码库 > Activity生命周期
Activity生命周期
public class MainActivity extends Activity {
private String tag = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(tag, "onCreat"); //Activity被系统实例化之后触发
}
@Override
protected void onStart() {
super.onStart();
Log.i(tag, "onStart()"); //onCreat或onRestart方法之后触发
}
@Override
protected void onResume() {
super.onResume();
Log.i(tag, "onResume()"); //onStart之后触发
}
@Override
protected void onPause() {
super.onPause();
Log.i(tag, "onStart()"); //使Activity处于暂停状态时触发
}
@Override
protected void onStop() {
super.onStop();
Log.i(tag, "onStop()"); //Activity处于停止状态时触发
}
@Override
protected void onRestart() {
super.onRestart();
Log.i(tag, "onRestart"); //从停止状态转变为运行状态时触发
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(tag, "onDestroy()"); //使Activity处于系统回收时触发
}
}
如有不足,欢迎指出。
Activity生命周期