Android: Temporarily disable orientation changes in an Activity?

As explained by Scienceprodigy in his self-answer calling.

As explained by Scienceprodigy in his self-answer, calling setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_NOSENSOR); and then setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_SENSOR); really works like charm... on real devices!

Don't think that it's broken when testing on the emulator, the ctrl+F11 shortcut ALWAYS change the screen orientation, without emulating sensors moves. EDIT: this was not the best possible answer. As explained in the comments, there are issues with this method.

The real answer is here.

I couldn't locate those constants. Thanks for that. – Christopher Perry Sep 2 '10 at 7:13 3 There's an issue with these methods... It looks like if you call setRequestedOrientation(ActivityInfo.

SCREEN_ORIENTATION_NOSENSOR); when the device is not in its default orientation usage, then the activity orientation is immediately changed (destroyed and recreated) to the device default orientation. For example, on a phone, if you hold it in landscape orientation, then the activity is switched to portrait and back to landscape when reactivating sensors. The same opposite issue with an Archos A5 IT : using it in portrait causes the activity to be switched to landscape and back to portrait.

– Kevin Gaudin Oct 30 '10 at 0:10 1 The real answer to the original question is there: stackoverflow. Com/questions/3821423/… – Kevin Gaudin Oct 30 '10 at 15:46.

Thanks all. I modified Pilot_51's solution, to make sure I restored to the previous state. I also threw in a change to support non-landscape and non-portrait screens (but haven't tested it on such a screen).

PrevOrientation = getRequestedOrientation(); if(getResources(). GetConfiguration(). Orientation == Configuration.

ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); } else if(getResources(). GetConfiguration().

Orientation == Configuration. ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.

SCREEN_ORIENTATION_NOSENSOR); } Then to restore it setRequestedOrientation(prevOrientation).

Good stuff--not sure why you didn't use a switch though. – GJTorikian Jun 23 at 20:49 Forgot to clean up and change to a switch after I added the third option. – ProjectJourneyman Jun 27 at 18:32.

I found the answer. To do this, in an Activity you can call setRequestedOrientation(int) with one of the values specified here: developer.android.com/reference/android/... Before I kicked off my thread I called setRequestedOrientation(OFF) (OFF = nosensor) and when the thread was done I called setRequestedOrientation(ON) (ON = sensor). Works like a charm.

None of the other answers did the trick perfectly for me, but here's what I found that does. Lock orientation to current... if(getResources(). GetConfiguration().

Orientation == Configuration. ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_PORTRAIT); } else setRequestedOrientation(ActivityInfo.

SCREEN_ORIENTATION_LANDSCAPE); When changing orientation should be allowed again, set back to default... setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_UNSPECIFIED).

Since no one seems to mention this part, you're going to want to import android.content.pm. ActivityInfo in order to use the ActivityInfo identifier.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions