Thursday, September 6, 2018

How to avoid restarting activity when orientation changes on Android

Credit goes to StackOverflow
I am creating an Android app in which I'm drawing a view on a canvas. When the device's orientation changes, the activity restarts. I don't want it to.
How can I avoid restarting the activity when the orientation changes?
 
Define your activity in the AndroidManifest.xml like this:
   <activity
        android:name="com.name.SampleActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:icon="@drawable/sample_icon"
        android:label="@string/sample_title"
        android:screenOrientation="portrait" >
    </activity>
 

No comments:

Post a Comment