views:

131

answers:

1

Is it possible to make an Activity temporarily not rotatable (like, turning it on/off in code, not in the manifest)?

One of my old apps crashes if you rotate while it's doing an HTTP lookup as the views are no longer attached when it returns. One of these days I'll fix it proper, but in the mean time it'd be useful if I could just make the thing not-rotatable while it's doing the lookup.

+1  A: 

I believe you can register to be notified of the orientation change events and override Activity.onConfigurationChanged. Register for orientation changes in the manifest with the configChanges attribute.

Then, of course, you can decide whether or not to rotate and call setRequestedOrientation.

Rich
I was afraid it would be trouble. If I'm going to that much effort I may as well just fix the original problem. I was really hoping I'd missed something simple like an `Activity.setOrientable(bool)`.
fiXedd
Nothing's ever that simple on Android. lol
Rich
This doesn't work as it is. I'm currently looking through the Android source code to try and figure out how to do this infuriatingly basic thing.
Max Howell