onAttch Activity与fragment建立关联
oncreate 执行新建状态
oncreateview 绘制Fragment对应视图
onstart-onpesume 页面运行在前台,可以跟用户进行交互
onpause-onstop-onDestoryview-onDestory-onDetch 当销毁的时候,Fragment带领Activity执行,
oncreate 执行新建状态
oncreateview 绘制Fragment对应视图
onstart-onpesume 页面运行在前台,可以跟用户进行交互
onpause-onstop-onDestoryview-onDestory-onDetch 当销毁的时候,Fragment带领Activity执行,
onDestory 解除关联
在清单文件文件配置
android横竖屏切换
默认什么都不设置
1,保存临时数据
2,configChanges="orientation|keyboardHidden|screenSize"控制横竖屏生命周期不重走
3,android:screenOrientation="portrait" 指定横(landscape)竖(portrait)屏
三个是不同的操作
默认什么都不设置
1,保存临时数据
2,configChanges="orientation|keyboardHidden|screenSize"控制横竖屏生命周期不重走
3,android:screenOrientation="portrait" 指定横(landscape)竖(portrait)屏
三个是不同的操作
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onStop() { super.onStop(); Log.d("A","onStop()"); } @Override protected void onPause() { super.onPause(); Log.d("A","onpause"); } @Override protected void onResume() { super.onResume(); Log.d("A","onResume"); } @Override protected void onDestroy() { super.onDestroy(); Log.d("A","onDestroy"); } @Override protected void onStart() { super.onStart(); Log.d("A","onStart"); } @Override protected void onRestart() { super.onRestart(); Log.d("A","onRestart"); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.d("A","onConfigurationChanged"); int orientation = newConfig.orientation; if (orientation==Configuration.ORIENTATION_PORTRAIT){ setContentView(R.layout.two); }else if (orientation== Configuration.ORIENTATION_LANDSCAPE){ setContentView(R.layout.san); } } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("page",100); Log.d("A","临时数据储存成功"); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); int page = savedInstanceState.getInt("page"); Log.d("A","回复临时数据成功"+page); }