1

Je souhaite que mon application gère les modifications d'orientation manuellement. Alors que la raison pour laquelle j'ai mis onConfigurationChanged(Configuration newConfig), comme ci-dessous:java.lang.IllegalStateException: getResources() a déjà été appelé

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

Mais, quand mon application est en cours d'exécution, et je viens de tourner mon appareil, puis, mon accident d'application et je reçois ces journaux:

12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich EXCEPTION FATALE: principale 12-11 13: 18: 47.522 22290 22290 E
AndroidRuntime fr.zwedge.becomerich Processus: fr.zwedge.becomerich, PID: 22290 12-11 13: 18: 47.522 22290 22290 E
AndroidRuntime fr.zwedge.becomerich
java.lang.IllegalStateException: getResources() a déjà été appelé 12-11 13: 18: 47,522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à android.view.ContextThemeWrapper.applyOverrideConfiguration (ContextThemeWrapper.java:64) 12-11 13: 18: 47,522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à fr.zwedge.becomerich.activity.MainActivity.onConfigurationChanged (MainActivity.java:1116) 11/12 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 2 2290 22290 E AndroidRuntime fr.zwedge.becomerich à android.app.ActivityThread.handleConfigurationChanged (ActivityThread.java:4113) 12-11 13: 18: 47,522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à android.app .ActivityThread $ H.handleMessage (ActivityThread.java:1435) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à l'adresse android.os.Handler.dispatchMessage (Handler.java:110) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
à l'adresse android.os.Looper.loop (Looper.java:193) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich au android.app.ActivityThread.main (Act ivityThread.java:5299) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
à java.lang.reflect.Method.invokeNative (Méthode native) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
à java.lang.reflect.Method.invoke (Method.java:515) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:829) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich à com.android.internal.os.ZygoteInit.main (ZygoteInit .java: 645) 12-11 13: 18: 47.522 22290 22290 E AndroidRuntime fr.zwedge.becomerich
à dalvik.system.NativeStart.main (Native Method)

Je ne sais pas ce qui va mal. En espérant que quelqu'un puisse m'expliquer, et m'aider, Darkball60

Répondre

0

La méthode ContextThemeWrapper.applyOverrideConfiguration ne peut être appelée qu'une seule fois et vérifie si des ressources ont été accédées. Vérifiez votre code si vous avez également un appel à applyOverrideConfiguration dans le constructeur, ce qui m'est arrivé une fois.

Vérifiez également le documentation.

+0

Vérifié cela, et non, je n'ai pas utilisé cette méthode auparavant. – Mesabloo