zoukankan      html  css  js  c++  java
  • android 转屏 onConfigurationChanged 不会执行的问题

    参考 http://blog.csdn.net/tangzhilu/article/details/7399988

    MainActivity 代码

    package com.example.configchangesample;
    
     
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.res.Configuration;
    import android.util.Log;
    import android.view.Menu;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
        
        TextView textView1;
        String TAG = "configchangesample";
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            textView1 = (TextView)this.findViewById(com.example.configchangesample.R.id.textView1);
            textView1.setText("init");
            Log.i(TAG, "onCreate");
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            textView1.setText("onConfigurationChanged");
            Log.i(TAG, "onConfigurationChanged:" + newConfig.orientation);
            
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
                textView1.setText("ORIENTATION_LANDSCAPE");
            } else {
                 
                textView1.setText("ORIENTATION_PORTRAIT");
            }
            
        }
    }

    如果是 如下的配置

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.configchangesample"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.configchangesample.MainActivity"
                android:label="@string/app_name"
                android:configChanges="orientation|screenSize" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>

    在android 4.2.2 真机 和 android 2.3.5 真机验证,onConfigurationChanged 会被执行。

    如果 android:configChanges="orientation|screenSize"  改为  android:configChanges="orientation" 

    在android 4.2.2 真机上验证,onConfigurationChanged 不会被执行。

    在android 2.3.5 真机上验证,onConfigurationChanged 会被执行。

    去掉   android:targetSdkVersion="18"  并且   android:configChanges="orientation" 

    在android 4.2.2 真机 和 android 2.3.5 真机验证,onConfigurationChanged 会被执行。

    另外,

    1.记得在手机上打开自动转屏的开关

    2.测试发现, 转屏时,无论如何 onCreate 不会被触发。

    网上的资料 加上keyboardHidden后onCreate 不会被触发,不加就会触发,这个解释貌似站不住脚。

    3. 反正记得一点,如果设置了android:targetSdkVersion ,记得加上screenSize

    解释比较罗嗦,点击这里查看 http://developer.android.com/guide/topics/manifest/activity-element.html
  • 相关阅读:
    ecshop /includes/lib_base.php、/includes/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.php Backdoor Vul
    ecshop /pick_out.php SQL Injection Vul By Local Variable Overriding
    dedecms /include/filter.inc.php Local Variable Overriding
    dedecms plusguestbook.php SQL Injection Vul By plusguestbookedit.inc.php
    帝国备份王(Empirebak) classfunctions.php、classcombakfun.php GETSHELL vul
    dedecms /member/uploads_edit.php SQL Injection Vul
    PHP Lex Engine Sourcecode Analysis(undone)
    dedecms /member/resetpassword.php SQL Injection Vul
    dedecms /member/reg_new.php SQL Injection Vul
    dedecms /member/pm.php SQL Injection Vul
  • 原文地址:https://www.cnblogs.com/xiaokang088/p/3540189.html
Copyright © 2011-2022 走看看