Android - Language change when clicking back -


i have settings section allow users change languages displayed within app. when user chooses different language, activity reloaded change of language can applied. problem is, when user clicks right after changing language, language shown in background activity still same. question is, should apply change of language when activity on background? suppose should detect change in onresume method, i'm not sure is. if have suggestions, please let me know. thank you.

after several attempts, have found solution problem. on oncreate method, sharedpreferences contains value of current language, , current language:

sharedprefrences languagepref = getsharedpreferences("language",mode_private); string language = languagepref.getstring("languagetoload", locale.getdefault().getdisplaylanguage()); 

then, in onresume method, assign value of above mentioned variable language local variable, , update value of language. compare these 2 variables - if different, destroy current activity , start another:

@override     public void onresume(){         super.onresume();                 string oldlanguage = language;         language = languagepref.getstring("languagetoload", locale.getdefault().getdisplaylanguage());         if (!oldlanguage.equals(language)){             finish();             startactivity(getintent());         }     } 

and voila, did trick!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -