参考 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

android 转屏 onConfigurationChanged 不会执行的问题的更多相关文章

  1. Android 中onConfigurationChanged问题

    onConfigurationChanged 不生效问题解决方案: 1).首先,需要重写onConfigurationChanged函数 @Override    public void onConf ...

  2. Android:关于onConfigurationChanged()的介绍(转)

    转载:http://www.cnblogs.com/bluestorm/p/3622444.html 从事Android开发,免不了会在应用里嵌入一些广告SDK,在嵌入了众多SDK后,发现几乎每个要求 ...

  3. android FragmentPagerAdapter getItem方法没有执行

    转自 http://blog.csdn.net/getchance/article/details/40263505 在一个 Android 应用中,我使用 FragmentPagerAdapter  ...

  4. Android Init进程命令的执行和服务的启动

    这里开始分析init进程中配置文件的解析,在配置文件中的命令的执行和服务的启动. 首先init是一个可执行文件,它的对应的Makfile是init/Android.mk. Android.mk定义了i ...

  5. Android之在linux终端执行shell脚本直接打印当前运行app的日志

    1.问题 我们一般很多时候会需要在ubuntu终端上打印当前运行app的日志,我们一般常见的做法是 1).获取包名 打开当前运行的app,然后输入如下命令,然后在第一行TASK后面的就可以看到包名 a ...

  6. android studio 程序真机执行中文显示乱码

    代码里中文显示正常,真机执行后中文显示乱码,解决的方法: build.gradle中加入一句 android { compileOptions.encoding = "GBK" }

  7. Win32窗口消息机制 x Android消息机制 x 异步执行

    如果你开发过Win32窗口程序,那么当你看到android代码到处都有的mHandler.sendEmptyMessage和 private final Handler mHandler = new ...

  8. linux系统下 android studio的 Terminal 中 执行 gradlew命令找不到

    错误显示: 原因是linux系统中优先查找的是PATH环境中的程序,并不是当前目录下,执行当前目录下的程序要加上./. 这个错误很明白了,没有gradlew的执行权限.可以ls -al查看下gradl ...

  9. Android中onTouch方法的执行过程以及和onClick执行发生冲突的解决办法

    $*********************************************************************************************$ 博主推荐 ...

随机推荐

  1. Android——Activity去除标题栏和状态栏

    一.在代码中设置 public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  //去 ...

  2. CAS (13) —— CAS 使用Maven Profile支持多环境编译

    CAS (13) -- CAS 使用Maven Profile支持多环境编译 摘要 CAS 使用Maven Profile支持多环境编译 版本 tomcat版本: tomcat-8.0.29 jdk版 ...

  3. Spark Shuffle原理解析

    Spark Shuffle原理解析 一:到底什么是Shuffle? Shuffle中文翻译为“洗牌”,需要Shuffle的关键性原因是某种具有共同特征的数据需要最终汇聚到一个计算节点上进行计算. 二: ...

  4. Extjs4.x treegrid,check-tree,locked getChecked() 方法错误

    当在treegrid中,锁定treecolumn列的时候,是无法通过执行getView().getChecked()获取选中的节点的,这是tree的一个bug, 详见:http://www.sench ...

  5. How MapReduce Works

    转自:http://blog.csdn.net/luyee2010/article/details/8624470 一.从Map到Reduce MapReduce其实是分治算法的一种实现,其处理过程亦 ...

  6. 输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。

    题目描述 输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数. 输入描述: 输入一个int型整数 输出描述: 按照从右向左的阅读顺序,返回一个不含重复数字的新的整数 输入例子 ...

  7. ps常用快捷键

    一. 二. 三.

  8. 第三百四十节,Python分布式爬虫打造搜索引擎Scrapy精讲—css选择器

    第三百四十节,Python分布式爬虫打造搜索引擎Scrapy精讲—css选择器 css选择器 1. 2. 3.  ::attr()获取元素属性,css选择器 ::text获取标签文本 举例: extr ...

  9. MyBatis打印输出SQL语句

    Hibernate是可以配置 show_sql 显示 自动生成的SQL 语句,用 format_sql 可以格式化SQL 语句,但如果用 mybatis 怎么实现这个功能呢?如果你搜索看一下,基本都是 ...

  10. AngularJS $http模块POST数据,后台接受不到

    1.问题: 后端接收不到AngularJs中$http.post发送的数据,总是显示为null 示例代码: $http.post(/admin/KeyValue/GetListByPage, { pa ...