zoukankan      html  css  js  c++  java
  • Android 面试之横竖屏切换的Activity生命周期

    public class EngineerJspActivity extends Activity {
        private static String Tag = "EngineerJspActivity";
    	@Override
    	protected void onCreate(Bundle savedInstanceState) { 
    		super.onCreate(savedInstanceState);
    		Log.d(Tag, "onCreate()");
    		setContentView(R.layout.activity_main);
    	}
    	@Override
    	protected void onStart() {
    		super.onStart();
    		Log.d(Tag, "onStart()");
    	}
        @Override
        protected void onResume() {
        	super.onResume();
        	Log.d(Tag, "onResume()");
        }
        @Override
        protected void onSaveInstanceState(Bundle outState) {
        	super.onSaveInstanceState(outState);
        	Log.d(Tag, "onSaveInstanceState()");
        }
        @Override
        protected void onPause() {
        	super.onPause();
        	Log.d(Tag, "onPause()");
        }
        @Override
        protected void onStop() {
        	super.onStop();
        	Log.d(Tag, "onStop()");
        }
     @Override
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
        	super.onRestoreInstanceState(savedInstanceState);
        	Log.d(Tag, "onRestoreInstanceState()");
        }
        @Override
        protected void onDestroy() {
        	super.onDestroy();
        	Log.d(Tag, "onDestroy()");
        }
    
    }
    ②执行Activity(没有切换屏幕的正常情况下启动Activity),得到例如以下结果:

    ③切换成横屏时的Activity生命周期:

    ④换回竖屏的Activity生命周期:

    ⑤给清单文件加上android:configChanges="orientation"属性。又一次启动Activity,没有切换屏幕时(正常启动)的生命周期:

    ⑥加上android:configChanges="orientation"属性。切换成横屏,Activity的生命周期:

    ⑦加上android:configChanges="orientation"属性。换回竖屏,Activity的生命周期:

    ⑧加上android:configChanges="orientation"keyboardHidden"属性。正常启动Activity的生命周期(未切屏幕):

    ⑨加上android:configChanges="orientation"keyboardHidden"属性。正常启动Activity的生命周期(切成横屏):

    ⑩加上android:configChanges="orientation"keyboardHidden"属性。正常启动Activity的生命周期(换回竖屏):

    执行Home键之后的生命周期:

  • 相关阅读:
    C#自定义控件之数字文本框
    C# 校验字符串是否为IP格式
    C# winform 解决加载闪烁,背景透明等问题
    SQL Server 数据类型
    C#自定义控件之下拉列表框
    C#将 byte[ ] 转换为对应的struct
    AFNetworking图片上传
    xfs删除oracle数据文件恢复
    揭秘String类型背后的故事——带你领略汇编语言魅力
    [批处理]截取for命令里面的变量%%i
  • 原文地址:https://www.cnblogs.com/llguanli/p/7294342.html
Copyright © 2011-2022 走看看