Android application restarts on orientation change

When I change orientation application restarts and I lost my current data.. I am using activity group which contain lots of activities when i change orientation application restarts from main activity.

is it possible to avoid this application restart on orientation change?

Anybody knows please let me know..


Solution 1:

if your android:targetSdkVersion="12" or less

android:configChanges="orientation|keyboardHidden">

if your android:targetSdkVersion="13" or more

android:configChanges="orientation|keyboardHidden|screenSize">

Solution 2:

Android restarts the activities whenever the orientation change by default.

You will need to save your data/state by calling onSaveInstanceState() before Android destroys the activities.

Have a look here: Handling Runtime Changes

This SO question also proves to be a good read in understanding how you could deal with it.

You could prevent this by adding android:configChanges="orientation" to your activity in AndroidManifest file.

Source: http://developer.android.com/guide/topics/manifest/activity-element.html#config