Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set orientation fixed for all activities

I know there are two ways to set an Activity's orientation to landscape, either programmatically

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or in the Manifest:

android:orientation="landscape"

Currently, I use the first one in a superclass, because I have many (child) activities that I all want to be always in landscape. However, this make onCreate being called twice, which leads to other issues. When using the Manifest-route, I have to apply it to all activities separately, which will undoubtedly lead to one being missed out in the future (not to mention all the code copying).

Is there a way to apply android:orientation="landscape" to all activities in my app?

like image 673
Bart Friederichs Avatar asked Oct 26 '25 15:10

Bart Friederichs


1 Answers

Or you can try make "superclass" for all activities and extends from "superclass".

public abstract class SuperActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState);
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
like image 157
Hippo Avatar answered Oct 28 '25 05:10

Hippo