屏幕旋转Activity的生命周期变化
屏幕旋转 Activity 的生命周期变化:
1、Activity 不重启请在 AndroidManifest.xml 设置如下:
......
<activity android:name=".app.CustomDialogActivity"
android:label="@string/activity_custom_dialog"
android:configChanges="orientation|keyboardHidden" >
......
2、如果不设置则启动如下:
第一次执行
onCreate(null)
onStart()
onPostCreate()
onResume()
onPostResume()
可将屏幕旋转以后:
onSaveInstanceState()
onPause()
onStop()
onDestroy()
onCreate(Bundle[{android:viewHierarchyState=Bundle[{android:views=android.util.SparseArray@43370a48}], key=123}])
onStart()
onRestoreInstanceState()
onPostCreate()
onResume()
onPostResume()
onDestroy() 证明杀掉了你的 activity, onCreate() 又重新启动了你的 activity
代码:
......
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog_activity);
Log.w("Test", "onCreate(" + savedInstanceState + ")");
}
protected void onRestart() {
super.onRestart();
Log.w("Test", "onRestart()");
}
protected void onStart() {
super.onStart();
Log.w("Test", "onStart()");
}
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.w("Test", "onRestoreInstanceState()");
}
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Log.w("Test", "onPostCreate()");
}
protected void onResume() {
super.onResume();
Log.w("Test", "onResume()");
}
protected void onPostResume() {
super.onPostResume();
Log.w("Test", "onPostResume()");
}
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("key", 123);
super.onSaveInstanceState(outState);
Log.w("Test", "onSaveInstanceState()");
}
protected void onPause() {
super.onPause();
Log.w("Test", "onPause()");
}
protected void onStop() {
super.onStop();
Log.w("Test", "onStop()");
}
protected void onDestroy() {
super.onDestroy();
Log.w("Test", "onDestroy()");
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.w("Test", "onNewIntent()");
}
.....
更多相关文章
- Android(安卓)GridView设置条目的高度与宽度相等、GridView条目
- android获得屏幕高度和宽度、状态栏高度
- Android(安卓)DataBinding ViewPage + Fragment 封装
- Android(安卓)数据库SQLite的使用简单Demo
- android 网络连接 HttpGet HttpPost方法
- 关于 android AES 部分机器 javax.crypto.BadPaddingException:
- Android添加room依赖的正确姿势(附带完整流程)
- Android(安卓)强制竖屏