I search on Google & stackoverflow but I can't solve my problem. I refer http://www.androhub.com/android-building-multi-language-supported-app/ I have the three activities (activity 1,2,3). Activity 1 > Activity 2 > Activity 3 (milti lang change). In Activity 3, I have the two radio button to change (en, hi). After I change language; go to first activity (Activity 1), it is ok. But I want to stay current activity (refresh current activity), after I choose a radio button (changed language). Otherwise, how to recall onCreate() when I go back onBackPressed(). How to do the best way to stay current activity after change language.
onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
txt = (MMTextView) findViewById(R.id.txt);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
pref = getSharedPreferences("MyPref", Activity.MODE_PRIVATE);
editor = pref.edit();
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
String lang = "en";
switch (i) {
case R.id.eng:
lang = "en";
Intent i1 = new Intent(Main3Activity.this, MainActivity.class);
i1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i1);
finish();
break;
case R.id.hi:
lang = "hi";
Intent i2 = new Intent(Main3Activity.this, MainActivity.class);
i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i2);
finish();
break;
default:
break;
}
changeLocale(lang);
}
});
loadLocale();
}
changeLocale
private void changeLocale(String lang) {
if (lang.equalsIgnoreCase(""))
return;
Locale myLocale = new Locale(lang);
saveLocale(lang);
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
saveLocale & loadLocale
private void saveLocale(String lang) {
editor.putString("save", lang);
editor.commit();
}
private void loadLocale() {
String lang = pref.getString("save", "");
changeLocale(lang);
}