2011-12-06

onSaveInstanceState called twice

When you rotate the android emulator, first time components keep their state, nothing is wrong, but second time, onSaveInstanceState is called twice, because the activity is instantiated twice, one for a little interval of time and other to keep visible. The first of this couple do not restore the previous state saved with onSaveInstanceState, so restoring it will clear the saved state. 

This only happens in the EMULATOR so this don't should concern anybody, but there is a workaround to prevent this problem that doesn't hurt you application. I you don't need to show the keyboard just add this to you activity manifest in AndroidManifest.xml

android:configChanges="keyboardHidden"

But it only works if you rotate slowly, if you rotate it twice just when the activity is restoring state you'll still have the same problem.

I get this here here


No hay comentarios: