When the Android system switches the language, the APP cannot update the resource file. androidapp
Your APP supports multi-language Environments. If it is running in the background, you can change the system language and open it directly from the background after the system language is changed, at this time, the user will find that your interface language is not consistent with the system language. Why? Mainly because the interface resources are not reloaded
If you set language switching in the APP, you can directly process the switching activity and restart the activity once, however, if your APP is similar to me and does not have the function of switching language, but follows the system, you cannot process it in all the activities! So I will restart the app in the application to solve the resource update problem.
We all know that Application is the first entry to Android, so once the system switches the language, it will trigger its onConfigurationChanged () method, and then we will process it directly in this method after restarting, the finishActivity (); method is to close all the activities, so you need to execute MyApp in BaseActivity. getInstance (). addActivity (this );
Public class MyApp extends Application {private static MyApp instance = null; private List <Activity> activities = new ArrayList <Activity> (); public void addActivity (Activity activity) {activities. add (activity);} public void finishActivity () {for (Activity activity: activities) {activity. finish () ;}} public static MyApp getInstance () {if (instance = null) {instance = new MyApp () ;}return instance ;}@ Override public void onCreate () {// TODO Auto-generated method stub super. onCreate (); instance = this ;}@ Override public void onConfigurationChanged (Configuration newConfig) {// TODO Auto-generated method stub super. onConfigurationChanged (newConfig); // configuration change triggers this method finishActivity (); // The language switch exits // The following method is directly used at the beginning, during the test, it is found that if the app starts multiple activities, this method will cause the app to restart several times, and finally the activity is closed in batches to solve the issue. // System. exit (0); // android. OS. process. killProcess (android. OS. process. myPid ());}}