When I change the orientation of the Android application, it calls onStop method and then onCreate. How to avoid caling onStop and onCreate when orientation changes?
It have been long time since this question have been active, but I sill need to answer this. I had same issue and found answer.
In manifest you should add android:configChanges=orientation|screenLayout|layoutDirection|screenSize
in your activity which should not call default actions on orientation change.
...
<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
This is the default behavior: the activity is recreated when orientation changes. But you can decide to ignore this event. You can find details here : How to make an application ignore screen orientation change?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With