akexorcist / Localization

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

App crashes first time using web view after setting a new language in the application. #114

Open CNdev16 opened 3 years ago

CNdev16 commented 3 years ago

App crashes first time using web view after setting a new language in the application. แอพจะแครชกรณีใช้งาน webview ครั้งแรกหลังจาก start app -> set language in app ครับ

ref:

huunhan18pro commented 3 years ago

I also get the same issue. Only for the first time. The library is very good. I could change any language on my app. But I got this issue. Hope you fix it soon. Ver 1.2.10 and Android 7.0

nagesh-kashyap-r commented 3 years ago

@akexorcist i'm facing same issue. App crashes for first time.

nagesh-kashyap-r commented 3 years ago

@akexorcist I found the scenario. if I change locale after retuning a different locale from getDefaultLanguage(base: Context). (for very first time)

Stupidman22 commented 3 years ago

any one have solution for this. The same issue here

nagesh-kashyap-r commented 3 years ago

@Stupidman22 @huunhan18pro @CNdev16 I resolved this issue.

You have to create a webview instance (programmatically) and destroy it. (just do it in on create). Find the helper class in the below link.

https://github.com/YarikSOffice/lingver/blob/master/sample/src/main/java/com/yariksoffice/lingver/WebViewLocaleHelper.kt

Not sure why it behaves like this. but it solved my problem.

Crash happens only if you inflate a webview via XML (first instance). Not sure, but maybe it is something to do with not refreshing application context after language change.

Please let me know if it resolves your issue.

Stupidman22 commented 3 years ago

Thank you so much. I will apply it 😁

On Sun, Jun 6, 2021, 22:44 nagesh-kashyap-r @.***> wrote:

@Stupidman22 https://github.com/Stupidman22 @huunhan18pro https://github.com/huunhan18pro @CNdev16 https://github.com/CNdev16 I resolved this issue.

You have to create a webview instance (programmatically) and destroy it. (just do it in on create). Find the helper class in the below link.

https://github.com/YarikSOffice/lingver/blob/master/sample/src/main/java/com/yariksoffice/lingver/WebViewLocaleHelper.kt

Not sure why it behaves like this. but it solved my problem.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/akexorcist/Localization/issues/114#issuecomment-855419073, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAGR55665YZZC7J44HLS6LTROJV5ANCNFSM45OXTLCQ .

Stupidman22 commented 3 years ago

The problem cause when using web view and override this function at application override fun getDefaultLanguage(): Locale { return Locale.getDefault() } --> any one try to reproduce and fix issue pls. I think this is critical issue

nagesh-kashyap-r commented 3 years ago

@Stupidman22 I solved the exact same issue by just creating an WebView() object.

Like WebView(context).destroy() ->> in onCreate() of activity

Did you try this?

Stupidman22 commented 3 years ago

@nagesh-kashyap-r : In my case the webview is Native ads of google. It load in activity first time. I try to using your solution. But it FC. I think I did something wrong :( ...

akexorcist commented 2 years ago

This issue was fixed in 1.2.11. Please check it out

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