0

I want to have portrait screen orientation in mobile view and both orientations in tablet view I didn't define orientation in manifest but I check if the device is not tablet make orientation portrait in code by this line:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

this code works in tablets perfectly but the problem occur when I try to run the app in landscape on tablets, first app runs in landscape and then change to portrait by code. so onCreate function run twice. I don't want to do this twice!

for example may I define a variable in values-sw600dp for example and use it to change orientation in manifest? or change manifest orientation priority?! (and set orientation in code?!)

Manishika
  • 5,478
  • 2
  • 22
  • 28
h.kelidari
  • 800
  • 1
  • 11
  • 20

1 Answers1

0

A work around that I had used, is to supply a main layout for tablets, and i add an invisible view "dummy_for_tablet" and from main activity

    @Override
    protected void onCreate(Bundle savedInstanceState)
    { 
         ....
         if( findViewById(R.id.dummy_for_tablet) != null)
         { //it's a tablet }
         else
         { //it's a mobile }
          ...
    }
Ahmad Dwaik 'Warlock'
  • 5,953
  • 5
  • 34
  • 56