Conditional restart on Activity onConfigurationChanged
android, android-activity, onconfigurationchanged, restart
Solution
if it's allowed call `setRequestedOrientation()`, when it's not allowed, do nothing.
As a tip: You can use `onRetainNonConfigurationInstance()` and `getLastNonConfigurationInstance()` and return (an object containing) the `AsyncThread`. This way the `Activity` will change orientation when the user wants to. Take note though: You shouldn't leak a reference to a `Context` (may it be a reference to your `Activity` or a `Drawable`, ...).
Problem
I want to make an activity that allows orientation changes on some condition, but not otherwise. More exactly I want to prevent restarting the activity when a background thread is busy. I have put the `configChanges` attribute on the activity manifest, and `onConfigurationChanged` is called when the orientation changes. However I want to allow the app to change the orientation when allowed. ``` @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (orientationChangeAllowed) { // how do I restart this activity? } else { // don't do anything } } ```