akexorcist / Localization

[Android] In-app language changing library
Apache License 2.0
983 stars 154 forks source link

ClassCastException on language change #89

Closed zhombie closed 3 years ago

zhombie commented 3 years ago

Exceptions occurs when language is changed. Sample project was used as example

Screenshot 2021-02-03 at 04 58 07
akexorcist commented 3 years ago

Hi @zhombie. Sorry for lately response

Could you give more information about testing device? This kind of issue might causing from Xiaomi's MIUI more than my library. Refer to https://stackoverflow.com/questions/64565156/miui-11-12-theme-switch-results-in-lifecycleexception-classcastexception

Besides the example code in the sample project. Is there any more code?

zhombie commented 3 years ago

Hi, not a problem, thanks for response.

Device info: Xiaomi Mi Note 9 Pro, MIUI 12.0.1

I already have forceDarkAllowed = false set for >29 sdk style. But it does not help. Yeap, it has other code near, but i don't think that other code can cause such problems

akexorcist commented 3 years ago

@zhombie Okay. Let me borrow the Xiaomi device from my colleague 😂

To reproduce this issue, just run the sample project in Xiaomi device. Is this right?

zhombie commented 3 years ago

Yeap, i have tried to reproduce the issue with the sample project, it gives me the same exception

akexorcist commented 3 years ago

@zhombie As I tested on Redmi Note 9 (MIUI 12.0.6). I got same error log without app crashing and language has changed properly.

E/ActivityInjector: get life cycle exception
    java.lang.ClassCastException: android.os.BinderProxy cannot be cast to android.app.servertransaction.ClientTransaction
        at android.app.ActivityInjector.checkAccessControl(ActivityInjector.java:24)
        at android.app.Activity.onResume(Activity.java:1859)
        at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:455)
        at com.akexorcist.localizationactivity.ui.LocalizationActivity.onResume(LocalizationActivity.kt:28)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1453)
        at android.app.Activity.performResume(Activity.java:8050)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4290)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4332)
        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:57)
        at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5368)
        at android.app.ActivityThread.access$3600(ActivityThread.java:233)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2081)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7561)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

This seem caused by calling Activity.recreate() in Xiaomi's firmware. Even I tried calling Activity.recreate() without language changing. So I have to say that a firmware issue and we can't fix this.

This is not only happen to my library. A few developers also found this problem from calling Activity.recreate() in Xiaomi's device.

zhombie commented 3 years ago

Yeap, it is fairly vendor's problem and everything works fine, just some unexpected things could happen. I opened issue, in order to know if you have solution to this issue

akexorcist commented 3 years ago

@zhombie You've done the great things. Even I can't solve this vendor's problem but I've learned about this as known issue. 😆

AlexSuvorov2k commented 3 years ago

Same problem on Redmi Note 10 👍