Stop App from Restarting when Screen is Rotated
avatar

One interesting problem I have encountered in Android development is that the when you rotate the device it restarts the activity from the start.  This is very annoying espeical to the end user who can get the splash screen again or have to start to from the begining of the app.

With a few simple lines of code you will be able to prevent this screen rotation from taking place.

Step 1:  Edit your android manifest.xml file to add in the following line to where the activity is displayed:

android:configChanges=”keyboardHidden|orientation”

Step 2:  Add the following to your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

This entry was posted in Android, Development and tagged , , . Bookmark the permalink.

Leave a Reply