onResume
按home键以后执行以下方法
onSaveInstanceState
当Activity中止时 再次调用onCreate 保存数据 用户密码 用户名 其他进行到一半的数据
onPause
onStop
重新进入Activity后执行
onRestart
onStart
onResume
按back键以后会执行以下方法
finish
onBackPressed
onPause
onStop
onDestory
由竖屏转横屏
onSaveInstanceState
onPause
onStop
onDestory
onCreate
onStart
onRestoreInstanceState
onResume
横屏变竖屏
onSaveInstanceState
onPause
onStop
onDestory
onCreate
onStart
onRestoreInstanceState
onResume
如果你什么都不干 只是横竖屏切换 相当于Activity被干掉 又起来了
在Activity中加入一个Button按钮 和一个onActivityResult方法
点击按钮打开自己这个Activity 调用的方法是
onSaveInstanceState
onPause
onCreate
onStart
onResume
onStop
当返回时会调用
finish
onBackPressed
onPause
onActivityResult
onRestart
onStart
onResume
onStop
onDestroy
android中还有一个方法onLowMemory
//当系统内存不足时 才会调用 但不一定会百分百调用 如果能及时调用则会调用
也可能在没用调用之前就将程序关闭了,那么就不会调用这个方法。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("info", "onCreate");
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivityForResult(intent, 10);
}
});
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
Log.i("info", "onRestoreInstanceState");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Log.i("info", "onActivityResult");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
Log.i("info", "onSaveInstanceState");
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("info", "onStart");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.i("info", "onRestart");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("info", "onResume");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("info", "onPause");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.i("info", "onStop");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("info", "onDestroy");
}
@Override
public void onLowMemory() {
// TODO Auto-generated method stub
super.onLowMemory();
//当系统内存不足时 才会调用 但不一定会百分百调用 如果能及时调用则会调用 可能在没用调用之前就将程序关闭了。
Log.i("info", "onLowMemory");
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Log.i("info", "onBackPressed");
//
}
@Override
public void finish() {
// TODO Auto-generated method stub
super.finish();
//要关闭Activity 所以才要调用finish()方法
Log.i("info", "finish");
}
}