Reputation: 14648
Is there a way I can start activity in a specific orientation (programmatically) without having it to be recreated again? Right now if I call setRequestedOrientation from the the OnCreate and the orientation is different than the current then the activity is destoryed and restarted again.
Thank you
Upvotes: 8
Views: 2016
Reputation: 340
For me solution was to lock orientation of Activity
android:screenOrientation="locked"
, and now it depends only on setRequestedOrientation():
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="locked">
No restarting anymore.
Upvotes: 6
Reputation: 98
If you don't want activity to restart, add configChanges for the activity in AndroidManifest.xml
<activity
android:name="com.myexample.SplashScreen"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
and then call setRequestedOrientation to set orientation programtically.
But if you want to lock the activity to 1 orientation. It is good to set it in Manifest by adding android:screenOrientation="portrait"
Upvotes: 1
Reputation: 510
You can set your orientation in Manifest file
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
Upvotes: 1