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?!)

2
  • so you want to check if it's a mobile or tablet? Oct 13, 2013 at 14:17
  • yes if is mobile only portrait orientation and if is tblet both orientation!
    – h.kelidari
    Oct 13, 2013 at 14:21

1 Answer 1

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 }
          ...
    }

Not the answer you're looking for? Browse other questions tagged or ask your own question.