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
2010-04-28 15:29:36
perfect!! thanks. didn't look with the right key word... sorry
Sephy
2010-04-28 15:35:09
Good, note that you can mark this as accepted answer.
LucaB
2010-04-28 15:40:55
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
2010-04-28 17:06:21
+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
2010-04-28 18:17:39