I already know how to change the language of my application (updating the configuration). My code also check if the configuration is changed by the system and "fix it" in the ´onCreate´ method. I even have created a ListPreference to let the user decide the language with one that my app supports (and saves the decision).
Let's say I have 3 activities (A, B and SettingsActivity). Activity A can start activities B and SettingsActivity. Activity B can start SettingsActivity. If the user changes the language inside SettingsActivity, I can update its resources (in this case Strings) without any problem using this code:
//if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
// Disabled because it blinks and looks bad
// recreate();
// } else {
startActivity(getIntent());
finish();
overridePendingTransition(0, 0);
// }
However, I'm unable to change the already open activities because I have no reference to them from SettingsActivity.
My question: is there any clean way to update the resources or recreate the already open activities? If I don't find a better solution, my approach will be one of the above:
- Start activities using
startActivityForResult
and return a code to trigger the code I already use to recreate the activity. - Check inside the
onResume
method if the current language has changed and do the same thing.