0

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.

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
Jeremy Logan
  • 47,151
  • 38
  • 123
  • 143

1 Answers1

1

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
  • 36,270
  • 31
  • 115
  • 154
  • 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)`. – Jeremy Logan Dec 04 '09 at 00:21
  • 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. – mxcl Feb 10 '10 at 13:42