2

I want my app to handle manually orientation changes. So that why I implemented onConfigurationChanged(Configuration newConfig), as below:

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        applyOverrideConfiguration(newConfig);
        super.onConfigurationChanged(newConfig);
    }

But, when my app is running, and I just turn my device, then, my app crash and I get these logs:

12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich FATAL EXCEPTION: main 12-11 13:18:47.522 22290 22290 E
AndroidRuntime fr.zwedge.becomerich Process: fr.zwedge.becomerich, PID: 22290 12-11 13:18:47.522 22290 22290 E
AndroidRuntime fr.zwedge.becomerich
java.lang.IllegalStateException: getResources() has already been called 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.view.ContextThemeWrapper.applyOverrideConfiguration(ContextThemeWrapper.java:64) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at fr.zwedge.becomerich.activity.MainActivity.onConfigurationChanged(MainActivity.java:1116) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:4037) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:4113) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1435) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.os.Handler.dispatchMessage(Handler.java:110) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
at android.os.Looper.loop(Looper.java:193) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at android.app.ActivityThread.main(ActivityThread.java:5299) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
at java.lang.reflect.Method.invokeNative(Native Method) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
at java.lang.reflect.Method.invoke(Method.java:515) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 12-11 13:18:47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
at dalvik.system.NativeStart.main(Native Method)

Don't know what's going wrong. Hoping someone can explain me, and help me, Darkball60

Ankita Shah
  • 1,866
  • 16
  • 31
Mesabloo
  • 337
  • 4
  • 13

1 Answers1

0

The method ContextThemeWrapper.applyOverrideConfiguration can be called only once, and it checks if resources have been accessed. Check your code if you also have a call to applyOverrideConfiguration in the constructor, that happened to me once.

Also check the documentation.

vladimir123
  • 484
  • 6
  • 12