屏幕方向更改的Android NullPointerException

har*_*hal 0 android android-orientation

我正在缩小并解释尽可能简单,主要活动启动异步任务.

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>
Run Code Online (Sandbox Code Playgroud)

har*_*hal 5

找到了解决方案......

android:configChanges ="orientation"不适用于片段

如果要在开发API级别13或更高级别(由minSdkVersiontargetSdkVersion属性声明)时由于方向更改而阻止运行时重新启动,则必须在screenSize值之外包含该orientation值.也就是说,你必须申报android:configChanges="orientation|screenSize".