I am working on an Android application that should be bilingual (English / Spanish). I allow the user to select the desired language from Preferences and perform the following locale changes in the main activity of the application (subclass TabActivity) based on the selected language:
private void setApplicationLanguage(String languageCode) {
In the main action, four tabs are placed, each of which has its own activity (sometimes an ActivityGroup). What I would like to have is when the language changes, all open actions just restart, which forces them to reload lines in the corresponding language. It would also be acceptable (but less desirable) to completely destroy all open actions, requiring the user to start the application again manually, and therefore all lines will be reloaded in the corresponding language.
I tried calling finish()
from the main action, which is why this activity stops. However, when I restart the application, the child actions "hosted" by the main action (one for each tab) are still displayed in the previous language. I guess this is because children's activities were not recursively "completed" for me.
I also tried to include / exclude the locale attribute from AndroidManifest.xml in the main action, as well as other actions, but I never see the activity restart when the local changes. Again, how will a โrestartโ manifest itself? Calling onCreate()
or just onResume()
or even something else? If this approach automatically restarted the action by calling onCreate()
when changing the locale, then this sounds like a concrete guide on how to do this, would be the best way in my case.
The solution should run at the Android 7 API level, so creating a new Intent
with the FLAG_ACTIVITY_CLEAR_TASK
flag is apparently not available.
source share