Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onstop method is called when Orientation changes

Tags:

android

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?

like image 972
indira Avatar asked May 11 '11 08:05

indira


2 Answers

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

like image 109
Karri Rasinmäki Avatar answered Sep 25 '22 23:09

Karri Rasinmäki


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?

like image 29
sdabet Avatar answered Sep 24 '22 23:09

sdabet