Home > other >  App restarted and the language changed when I change some permission to deny from setting in Android
App restarted and the language changed when I change some permission to deny from setting in Android

Time:03-09

I'm developing an Android app with two languages (English - Arabic) , my app is an Activity that contains Fragments I'm handling changing of the language across the app correctly but guys when the app language is Arabic then change any permission to deny from setting and open the app again , my app is restarting and the app language converted to be English

I already save the language in the Sharedpreferences , language is saved as Arabic correctly and the app works fine in all cases , but when changing permission from setting to deny , All strings converted to English and views directions change.

I tried to change the local in the onRestart() but it doesn't work , so any suggestion to solve this problem ?

If it would help , I'm changing the language in Splash screen based on the saved value from sharedpreference

 public void setLocal(String lang) {


        Resources res = this.getResources();
        Configuration conf = res.getConfiguration();
        conf.locale = new Locale(lang);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            conf.setLayoutDirection(new Locale(lang));
        }
        res.updateConfiguration(conf, res.getDisplayMetrics());
        Consts.first_lang_choose = true;
        

    }

CodePudding user response:

I'm changing the language in Splash screen

You need to have Locale override in all your activities. The Android framework can kill your activities (or even your app) and later restore it to the activity where it was, not going though your entry point activity such as a splash screen.

CodePudding user response:

You need to check if you propperly save the language change even when the app restarts.

It is normal that the app restarts if you revoke a permission from the android settings.

  • Related