0

We can write the following orientation to force each individual activities orientation.

android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"

Can we perform within application level? That is; instead of writing for every activity write once.

kelalaka
  • 5,064
  • 5
  • 27
  • 44

2 Answers2

2

Can we perform within application level?

No! you can not set screenOrientation for <application tag. You have to provide this to each Activity.

If you ask me common way to do this-

Make BaseActivity.java and set orientation in it's orientation. Now extend all your Activities from BaseActivity.java.

Either Programatically

public class BaseActivity extends AppCompactActivity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

}

Or in manifest.xml

 <activity
        android:name=".BaseActivity"
        android:screenOrientation="landscape"/>
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
2

This is the solution for your requirement

Create a BaseActivity then extend this activity to all activities just like this

public class MainActivity extends BaseActivity {

and add these lines to activity tag in manifest file

          <activity
            android:name=".BaseActivity"
            android:screenOrientation="landscape"
            android:configChanges="orientation|keyboardHidden" />
Quick learner
  • 10,632
  • 4
  • 45
  • 55