How to lock screen orientation and receive notifications of orientation changes

I want to block the orientation of the application to the portrait, but still get orientation changes. So I tried to add the android:screenOrientation="portrait" attribute to block the orientation and the android:configChanges="keyboardHidden|orientation" attribute to receive orientation change events in the ovverriden onConfigurationChanged method. However, the method is not called. Is there any way to achieve this?

Thanks a lot, Gratzi

+4
source share
3 answers

By forcing the orientation of your activity in portrait mode, you cannot receive orientation changes.

+1
source

Check the Manifest.xml file. It should look like this:

  <activity android:name="YourActivity1" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan" android:configChanges="orientation|keyboardHidden"></activity> <activity android:name="YourActivity2" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan" android:configChanges="orientation|keyboardHidden"></activity> 

+1
source

Are you sure you are writing this for your main activity <activity android: screenOrientation = "portrait" ...

-1
source

All Articles