1

I am now working on an android application, that is just gonna be for demo purposes. So during the development of the project, we didn't focus a lot on the orientation changes to the application. Whenever there is an orientation change, the application crashes. It is now too late to maintain the data for each activity or fragment.

So my question is, is there a way to set the orientation to potrait throughout the application. Even if the user rotates the phone, can we maintain the state to be potrait?

Ramji Seetharaman
  • 524
  • 4
  • 7
  • 24
  • 1
    try this https://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only – Vigen Aug 22 '17 at 19:39

2 Answers2

2

TL;TR: add this to your AndroidManifest.xml

<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>

You can checkout this answer as well.

Caue Ferreira
  • 287
  • 2
  • 7
1

From Java:

@Override
public void onCreate(Bundle 
savedInstanceState){ 

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

From XML:

<activity
    android:name=".ActivityName"
    android:label="@string/app_name"
    android:screenOrientation="portrait" />
Razvan
  • 292
  • 2
  • 3
  • 15