Avoid restarting activity when orientation changes on android

Stop and disable android activity restart after rotate screen to landscape mode.

On every single one android application project there is a by default configuration that is each and every time after rotating your android device and changing your screen orientation mode to landscape it will restart your whole android activity. App developer can easily stop activity restart by simply adding single line code into AndroidManifest.xml file. So here is the complete step by step tutorial for Avoid restarting activity when orientation changes on android.

Avoid restarting activity when orientation changes on android

How to Avoid restarting activity when orientation changes on android.

Add android:configChanges=”keyboardHidden|orientation|screenSize” into your AndroidManifest.xml file inside activity tag just like have done below.

Code for AndroidManifest.xml file.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.stopactivityrestart_android_examples.com"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name"
 android:configChanges="keyboardHidden|orientation|screenSize" >

 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

 

Leave a Reply

Your email address will not be published. Required fields are marked *