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
android 转屏 onConfigurationChanged 不会执行的问题的更多相关文章
- Android 中onConfigurationChanged问题
onConfigurationChanged 不生效问题解决方案: 1).首先,需要重写onConfigurationChanged函数 @Override public void onConf ...
- Android:关于onConfigurationChanged()的介绍(转)
转载:http://www.cnblogs.com/bluestorm/p/3622444.html 从事Android开发,免不了会在应用里嵌入一些广告SDK,在嵌入了众多SDK后,发现几乎每个要求 ...
- android FragmentPagerAdapter getItem方法没有执行
转自 http://blog.csdn.net/getchance/article/details/40263505 在一个 Android 应用中,我使用 FragmentPagerAdapter ...
- Android Init进程命令的执行和服务的启动
这里开始分析init进程中配置文件的解析,在配置文件中的命令的执行和服务的启动. 首先init是一个可执行文件,它的对应的Makfile是init/Android.mk. Android.mk定义了i ...
- Android之在linux终端执行shell脚本直接打印当前运行app的日志
1.问题 我们一般很多时候会需要在ubuntu终端上打印当前运行app的日志,我们一般常见的做法是 1).获取包名 打开当前运行的app,然后输入如下命令,然后在第一行TASK后面的就可以看到包名 a ...
- android studio 程序真机执行中文显示乱码
代码里中文显示正常,真机执行后中文显示乱码,解决的方法: build.gradle中加入一句 android { compileOptions.encoding = "GBK" }
- Win32窗口消息机制 x Android消息机制 x 异步执行
如果你开发过Win32窗口程序,那么当你看到android代码到处都有的mHandler.sendEmptyMessage和 private final Handler mHandler = new ...
- linux系统下 android studio的 Terminal 中 执行 gradlew命令找不到
错误显示: 原因是linux系统中优先查找的是PATH环境中的程序,并不是当前目录下,执行当前目录下的程序要加上./. 这个错误很明白了,没有gradlew的执行权限.可以ls -al查看下gradl ...
- Android中onTouch方法的执行过程以及和onClick执行发生冲突的解决办法
$*********************************************************************************************$ 博主推荐 ...
随机推荐
- Bitcoin A First Assessment
1. What is BitcoinBitcoin is a digital currency designed by Satoshi Nakamoto. Bitcoin allows users t ...
- PostgreSql 函数
DECLARE curParkingTime TIMESTAMP ; curLeavingTime TIMESTAMP; parkingSpaceIndexCode VARCHAR[]; days I ...
- CentOS服务器简单判断CC攻击的命令
使用下面的命令,可以分析下是否在被CC攻击. 第一条命令: tcpdump -s0 -A -n -i any | grep -o -E '(GET|POST|HEAD) .*' 正常的输出结果类似 ...
- sqoop 兼容性问题
--direct 只支持mysql 5.0 + 和postgresql 8.3+(只是import) jdbc的jar包需要放在$SQOOP_HOME/lib目录下 mysql zeroDateTim ...
- SQL Server创建远程链接服务器
--使用sp_addlinkedserver增加链接 EXEC sys.sp_addlinkedserver @server='127.0.0.1', --被访问的服务器别名(习惯上直接使用目标服务器 ...
- office2016选择性安装
office2016在安装的时候并不像之前的版本有选择性的安装,安装器会安装一个office全家桶.那么如何自主选择安装自己需要的工具呢? 微软在下载中心中提供了Office2016部署工具(Offi ...
- MFC函数—— CFrameWnd::OnCreateClient
CFrameWnd::OnCreateClient virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext*pContext); ...
- linux 木马清理过程
服务器出现异常,完全无法访问,ssh登陆都极其缓慢 解决过程 top 查看系统状态,发现 load average 平均负载值非常高,再看排名第一的进程,是一个不认识的进程名:minerd 感觉是被入 ...
- QSocket类
QSocket类提供了一个有缓冲的TCP连接. 详情请见…… #include <qsocket.h> 继承了QObject和QIODevice. 所有成员函数的列表. 公有成员 enum ...
- 访问网站出现EOF
HTTP/0.0 503 Service Unavailable Date: Tuesday, 18-Apr-17 10:29:46 CST Keep-Alive: timeout=38 EOF 今天 ...