2014-01-23 189 views
1

旋轉時出現問題。不希望的OnCreate再次運行旋轉問題Android

這是代碼 ---->清單

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/> 

---->清單

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:configChanges="keyboard|keyboardHidden|orientation"> 
</activity> 

---->活動

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
} 

請幫幫我

回答

1

1 -您可以通過在manifest中將android:screenOrientation="portrait"(或"landscape")添加到<activity>來鎖定某個方向的活動。

2 -你可以告訴你的意思是通過在<activity>標籤指定android:configChanges="screenOrientation"來處理自己的屏幕變化的系統。這樣,活動將不會被重新創建,但會收到一個回調(您可以忽略,因爲它對您沒有用處)。

就我個人而言(2)。當然,如果將應用程序鎖定在其中一個方向上並沒有問題,那麼也可以使用(1)。

根據您所選擇的選項,你的活動應該聲明如下:

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:screenOrientation="portrait" 
    android:configChanges="keyboard|keyboardHidden|orientation"> 
</activity> 

2-

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenOrientation"> 
</activity> 

爲筆記Android 3.2+(API 13) - 從此版本開始,屏幕旋轉也會導致屏幕大小發生變化l刷新UI。您需要聲明「orientation|screenSize」而不是「orientation」。 http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

+0

您好,感謝 嘗試添加清單 screenOrientation b ut我得到錯誤 錯誤:錯誤:字符串類型不允許(在'configChanges'值'keyboard | keyboardHidden |定位| screenOrientation')。 –

+0

@ user2493770你在那個應用上使用了android api版本? –

+0

嗨,謝謝.. 我正在使用的版本 Android 2.3.3 api等級10 幫我 –

0

按照Android docs for the configChanges attribute

Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

你應該改變

android:configChanges="keyboard|keyboardHidden|orientation" 

android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
+0

您好,感謝 嘗試添加清單 屏幕尺寸 但我得到錯誤 錯誤:錯誤:字符串類型不允許(在「configChanges」,值爲「鍵盤| keyboardHidden |方向| 屏幕尺寸」)。 –