Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top