Search code examples
androidandroid-orientation

Detect orientation change, when only portrait is allowed on Android


I have to solve the following: I have an Activity which's android:screenOrientation="portrait". Even though, when the device is rotated to landscape while this Activity is visible, I have to start another one, and, when the device is rotated back to portrait, I have to finish() the activity in landscape. I tried to perform this with a BroadcastReceiver, but this special activity doesn't receive any broadcasts because of the android:screenOrientation="portrait". Any help is well appreciated.

Thanks.


Solution

  • When android:screenOrientation="portrait" or "landscape" are set in the menifest file no listeners are fired still if u want to do it try handling the portrait only mode in ur onConfigurationChanged() programatically and here u will also be able to start the activity again.