How to save application language settings after device reboot?

My application has a language setting feature. Now it works fine, but after restarting the device, the language returns to the original setting.

Does anyone have any ideas? Do I need to implement SharedPreferences ?


I got an answer. If your application has a language setting. and after restarting, the last language you changed will still be used by default. One way to make this work is to save the variable via SharedPreferences ; may be a string language.

Another thing, you need to have an initiate class. so whenever you open the application. he is able to call.

for instance

Setting appSettings = Setting.getInstance(getApplicationContext());

language = appSetting.getLanguage();

appSetting.setLanguage(language);

+4
source share
4 answers

Yes, the best option is to use SharedPreferences.

Here you can find the tutorial: http://www.sgoliver.net/blog/?p=1731

Hope this helps ...

+3
source

In fact, you should use the SharedPreferences variable to store the active language.

+3
source

If they have not changed the situation, changing the language standard based on activity is a bad idea. Instead, you should start working with your deviceโ€™s language settings using this step.

+1
source

You do not need to use SharedPreferences , but rather the android:configChanges="locale" attribute in your manifest. If you change the current locale, then activity will remember it for you.

0
source

Source: https://habr.com/ru/post/1384920/


All Articles