Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity still recreated with configChanges

Tags:

android

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.

like image 811
Richard Eng Avatar asked Nov 05 '22 07:11

Richard Eng


1 Answers

Your screen size changes from 1200x800 to 800x1200 (for instance).

Since API 13, this will also raise a screenSize config change. The fix is:

android:configChanges="keyboardHidden|oritentation|screenSize"
like image 64
rds Avatar answered Nov 11 '22 06:11

rds