Onstop method called when orientation changes

When I change the orientation of the Android application, it calls the String method and then onCreate. How to avoid polling onStop and onCreate when changing orientation?

+4
source share
3 answers

It has been a long time since this question was active, but I still have to answer it. I had the same problem and found the answer.

In the manifest, you must add to your activity android:configChanges=orientation|screenLayout|layoutDirection|screenSize, which should not trigger default actions when you change the orientation.

...
<activity android:name=".Activity"
  android:screenOrientation="portrait"
  android:configChanges="orientation|screenLayout|layoutDirection|screenSize" 
...


And in your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
    // This overrides default action
}



Original example:
http://android-er.blogspot.fi/2011/05/prevent-activity-restart-when-screen.html

+7
source

: . . : ?

+2

You cannot avoid this; these are system callbacks. You can save the state, albeit in onStop, and then transfer it to the onCreate system for faster restoration of the state after changing the screen orientation.

See also this and that article about the page developer.

0
source

All Articles