akexorcist / Localization

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

Crash on checkLocaleChange #136

Open julienherrero opened 2 years ago

julienherrero commented 2 years ago

Because of the lateinit var, currentLanguage can be used before its initialization :

2022-04-26 11:54:34.654 4223-4223/com.tabesto.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.tabesto.myapp, PID: 4223
    kotlin.UninitializedPropertyAccessException: lateinit property currentLanguage has not been initialized
        at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate.checkLocaleChange(LocalizationActivityDelegate.kt:175)
        at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate.access$checkLocaleChange(LocalizationActivityDelegate.kt:12)
        at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate$onResume$1.run(LocalizationActivityDelegate.kt:37)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8653)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

You can facing this issue by using Direct-Boot : with this, we cannot initialize language before first onResume() call.

I've submited a PR to fix this : https://github.com/akexorcist/Localization/pull/135

akexorcist commented 2 years ago

Since AndroidX AppCompat has per-app language preferences for backward compatibility. Please migrate this library to AndroidX for more stability, compatibility, and longer support from Google team.

See Migrate to AndroidX guide

Thank you for your support