When I open an Activity I want that activity to remain in that orientation that was opened.
For example, if I open it in PORTRAIT mode, then the user wont’ be able to change it to landscape, and when I open it in LANDSCAPE, then the user won’t be able to change to portrait. (I need this for a video player)
To achieve this I get the current screen orientation, and then set it, like this:
int orientation = getResources().getConfiguration().orientation;
setRequestedOrientation(orientation);
If I open the Activity in PORTRAIT mode, and try to switch to LANDSCAPE by rotating the phone, it doesn’t – this is as expected. The issue is that if the activity is opened in LANDSCAPE and I attempt to rotate to portrait – it does.
I don’t understand why this might happen.
The code appears in the onCreate(), above the setContentView()
The problem is that
getResources().getConfiguration().orientationandsetRequestedOrientation(orientation);work with different constants. You could try reading the documentation for both of them, and doing the mapping between them.