Android - Let the activity remain in its original Orientation

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()

Answers


The problem is that getResources().getConfiguration().orientation and setRequestedOrientation(orientation); work with different constants. You could try reading the documentation for both of them, and doing the mapping between them.


Try with this:

@Override
    public void onResume() {
        super.onResume();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

    }

Need Your Help

Usage of custom and generic vertex shader attributes in OpenGL and OpenGL ES

opengl opengl-es glsl shader rendermonkey

Since generic vertex attributes are deprecated in OpenGL, I tried to rewrite my vertex shader using only custom attributes. And I didn't work for me. Here is the vertex shader:

Retrieve the unique websites from an url list

regex

I have a list with a lot of page urls. I want to retrieve the unique websites.