First we need to add proper XML attribute for our Game activity in the application manifest as follow.
Using xml Syntax Highlighting
- <activity android:name=".Game"
- android:launchMode="singleTask"
- android:configChanges="orientation|keyboardHidden"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
If we don't have that android:configChanges="orientation|keyboardHidden" line, we will have the following error :
E/WindowManager( 875): android.view.WindowLeaked: Activity com.domain.tester3.Engine.Game has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@437592e0 that was originally added here
and all sort of other errors in addition to that one depending on your codes.
Next we need to make sure that super.onSaveInstanceState() is called.
Using java Syntax Highlighting
- @Override
- protected void onSaveInstanceState(Bundle savedInstanceState){
- super.onSaveInstanceState(savedInstanceState);
- Log.d(TAG,"onSaveInstanceState");
- }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Since using android:configChanges="orientation|keyboardHidden" will by pass onDestroy and onCreate, you need to update your activity layout again by calling onConfigurationChanged()
Using java Syntax Highlighting
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- Log.d(TAG, "onConfigurationChanged");
- setContentView(R.layout.gamelayout);
- // you are other code here
- }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Now you can create AlertDialog that will survive the Orientation change.
rgds,
win


