1

I have a android 6.0.1 tablet. My activity is here using following orientation settings:

 <activity
                android:name=".MainActivity"
                android:screenOrientation="sensorLandscape"
                android:label="@string/app_name"
                android:windowSoftInputMode="adjustResize|stateHidden"
                android:configChanges="keyboardHidden|orientation|screenSize|uiMode">

When i turn tablet into 180 degree application activity rotate but problem is that when i turn on and off screen using power button on tablet while tablet is in 180 degree, application took few second to rotate. This was not happing in older android version. Is there any android activity setting which i can use to keep remember last screen orientation and keep it same either tablet screen turn off and on ?

user565
  • 871
  • 1
  • 22
  • 47
  • can you check this it might help you to understand more https://stackoverflow.com/questions/9561320/android-how-to-turn-screen-on-and-off-programmatically – Prags Nov 22 '17 at 13:16
  • Do you know which layout param should help to keep the state of screen orientation ? – user565 Nov 22 '17 at 13:22
  • that happens because your lockscreen application enforces your device to certain orientation when it is running. If there wes no lock screen, or it didn't enforce, then it would work as you want. So now it works this way: you rotate device way you need, and poser off, lock screen app is launched and enforces some orientation, you power device on, unlock screen (finish lock screen app), your app comes to foreground, and then applies it's orientation. – Vladyslav Matviienko Nov 22 '17 at 13:23
  • @VladMatvienko, I dont have any lockscreen enable on device. getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); – user565 Nov 22 '17 at 13:27
  • @VladMatvienko Well disabling a keyguard is helping now. I am currently doing like this in onCreate: KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard(); – user565 Nov 22 '17 at 13:45

1 Answers1

0

Simply use this in onCreate of your activity to disable rotation of activity when screen turn on and off:

((KeyguardManager)getSystemService("keyguard")).newKeyguardLock("keyguard").disableKeyguard();
user565
  • 871
  • 1
  • 22
  • 47