I have a main activity (let's call it A) and a second activity (let's call it B) which's used to change the language of the app. The point is, when I click the button to change the language I also call recreate();
and B changes it language. Until here it's ok. The problem comes when I go back to the main activity (A) and it hasn't updated the language because it hasn't been recreated, so, is there any way to recreate A from B in order to update A?
I use this code to translate the app (eng version example):
public void btnIngles_onClick(View v)
{
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
this.getApplicationContext().getResources().updateConfiguration(config, null);
recreate();
}
1) Activity B
changes some global settings, accessible via SharedPreferences
for example
2) In Activity A
do:
@Override
protected void onResume() {
super.onResume();
if(didLanguageChange)
recreate();
}
Problem solved. Activity A
will call onResume()
since it has switched into a paused state when Activity B
came into the foreground.