我正在缩小范围,尽可能简单地解释,主活动启动一个异步任务。
当方向改变时,onCreate()被召回,因此Async被创建一次增益。因此,在onPreExecute()中,我锁定我的方向,在onPostExecute()中,我释放方向锁定。这样,如果Async任务已经启动,则永远不会创建另一个任务实例。
另一个问题已经开始,在主活动本身中,当我随机地更改屏幕方向时,findViewById()返回null。每5-6次试一次。
怎么处理这个?任何帮助
onCreate()是否在方法或主线程完成后被重新调用?或者,一旦改变方向,它是瞬间的吗?
谢谢
?更新。
<application
android:allowBackup="true"
android:icon="@drawable/ap_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="agilepoint.android.mobilebpm.main.LoginActivity"
android:configChanges="orientation"
android:label="@string/app_name"
android:logo="@drawable/menu_button"
android:windowSoftInputMode="adjustPan|stateHidden"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent-filter>
</activity>
</application>发布于 2014-04-24 07:06:55
找到了我的解决方案。
android:configChanges="orientation" does not work with fragments
如果要防止在为API级别13或更高级别开发时由于方向更改而重新启动运行时(如minSdkVersion和targetSdkVersion属性声明的那样),则除了orientation值之外,还必须包含screenSize值。也就是说,您必须声明android:configChanges="orientation|screenSize"。
发布于 2014-04-23 08:41:17
为清单中的活动添加android:configChanges=“方向”。
https://stackoverflow.com/questions/23238882
复制相似问题