我在告訴Android在方向更改時不要調用onCreate()
時遇到問題。我已將android:configChanges="orientation"
添加到我的清單中,但仍在調用方向更改onCreate()
時調用。這是我的代碼。Android onConfigurationChanged未被調用
AndroidManifest.xml中
<activity android:name="SearchMenuActivity" android:theme="@android:style/Theme.NoTitleBar" android:configChanges="orientation"></activity>
SearchMenuActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the current layout to the search_menu
setContentView(R.layout.search_menu_activity);
Log.d(TAG, "onCreate() Called");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
//don't reload the current page when the orientation is changed
Log.d(TAG, "onConfigurationChanged() Called");
super.onConfigurationChanged(newConfig);
}
而且我logcat的輸出
06-23 12:33:20.327: DEBUG/APP(2905): onCreate() Called
//Orientation Changes
06-23 12:33:23.842: DEBUG/APP(2905): onCreate() Called
有誰知道我做錯了嗎?謝謝。
對我來說,訣竅是使用 android:configChanges =「orientation | keyboardHidden | screenSize」 –