簡體   English   中英

屏幕方向更改時Android NullPointerException

[英]Android NullPointerException on Screen Orientation Change

我正在縮小范圍並盡可能簡單地進行解釋,主要活動將啟動一個異步任務。

調用方向更改后,將調用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>

找到我的解決方案...

android:configChanges =“ orientation”不適用於片段

如果要防止在為API級別13或更高版本開發時(由於minSdkVersiontargetSdkVersion屬性聲明)方向改變而導致運行時重新啟動,則除orientation值外,還必須包括screenSize值。 也就是說,您必須聲明android:configChanges="orientation|screenSize"

為清單中的垂直活動添加android:configChanges =“ orientation”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM