Prevent screen rotation on Android

Sephy picture Sephy · Apr 28, 2010 · Viewed 226k times · Source

I have one of my activities which I would like to prevent from rotating because I'm starting an AsyncTask, and screen rotation makes it restart.

Is there a way to tell this activity "DO NOT ROTATE the screen even if the user is shaking his phone like mad"?

Answer

lbedogni picture lbedogni · Apr 28, 2010

Add

android:screenOrientation="portrait" 

or

 android:screenOrientation="landscape" 

to the <activity> element/s in the manifest and you're done.