views:

1765

answers:

2

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. So is there any way to tell this activity "DO NOT ROTATE the screen even if the user is shaking his phone like mad"?

+10  A: 

Add android:screenOrientation="portrait" to the element in the manifest or landscape and you're done.

LucaB
perfect!! thanks. didn't look with the right key word... sorry
Sephy
Good, note that you can mark this as accepted answer.
LucaB
Please note this is just hiding a bug in your app, making it less likely for users to trip over it. But they still will. Any configuration change can cause your activity to restart. You really need to write your activity correctly to deal with the async task as it restarts.
hackbod
+3  A: 

You can deal with screen orientation change and AsyncTasks. Preventing screen orientation changes is just a lazy workaround. And it's not hard to keep an AsyncTask alive across orientation changes :)

Romain Guy