标签:android开发
activity首次启动
:执行顺序onCreate——>onStart——>onResume
截图
package com.river.activitylife;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("life", "MainActivity onCreate");
}
public void loadSecond(View view) {
startActivity(new Intent(this, SecondActivity.class));
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("life", "MainActivity onDestroy");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("life", "MainActivity onResume");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("life", "MainActivity onStart");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.i("life", "MainActivity onStop");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("life", "MainActivity onPause");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.i("life", "MainActivity onRestart");
}
}
activity结束
:执行顺序:自身onPause——>自身onStop——>自身onDestroy
截图
activity跳转到其他Activity
:执行顺序:自身onPause——>其他onCreate——>其他
截图
package com.river.activitylife;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SecondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.i("life", "SecondActivity onCreate");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("life", "SecondActivity onDestroy");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("life", "SecondActivity onPause");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.i("life", "SecondActivity onRestart");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("life", "SecondActivity onResume");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("life", "SecondActivity onStart");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.i("life", "SecondActivity onStop");
}
}
activity跳转到主Activity
:执行顺序:最好看图
截图
标签:android开发
原文地址:http://blog.csdn.net/c_major/article/details/45483785