As I understand it, if you insert ‘android:configChanges=”orientation”‘ into the activity in the manifest, the activity will not be destroyed and recreated on an orientation change. To test this, I created a dead-simple app which does NOTHING. Then I inserted ‘android:configChanges=”orientation”‘ in the manifest. Then I added the following method:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.v(TAG,"onConfigurationChanged:");
super.onConfigurationChanged(newConfig);
}
However, I’m still seeing onCreate() being called. The activity is still being recreated.
As if that weren’t strange enough, I don’t see onConfigurationChanged() being called when I put the emulator into landscape mode (Ctrl-F11). It’s only called when I go back to portrait mode. Shouldn’t it be called both ways? Isn’t the configuration (orientation) being changed when I go into landscape as well as portrait modes? This makes no sense.
Anyway, this whole activity and orientation thing is driving me crazy.
The emulator emulates a device with a side-slider keyboard. The
android:configChangesvalue that matches your – would bekeyboardHidden, generally used in conjunction withorientationto handle non-keyboard devices (e.g.,android:configChanges="keyboardHidden|orientation").That being said,
android:configChangesis not recommended in most cases. Use dynamic fragments andsetRetainInstance(true), or useonSaveInstanceState()andonRetainNonConfigurationInstance()to allow the activity to be destroyed and recreated.