Your app supports multi-lingual environment, if it is running in the background, when the user to change the system language, and so on, and so on the system language to open it directly from the background, users will find that your interface language is not consistent with the system language; The main interface resource is not reloaded
If you are a part of your own in the app to set the language switch, then you can directly in the activity that you set the switch to do processing, restart the activity can be, but if your app and I do not have to switch language function, just follow the system, Then you can't handle it in all the activity! So I'm just going to restart the app right here in the application to fix the update resource problem.
We all know that in application is the first entry of Android, then once the system switches the language, it will trigger its onconfigurationchanged () method, then reboot we will be processed directly in this method, Finishactivity () Here, the method is to shut down all activity, then in the baseactivity need to execute myapp.getinstance (). addactivity (this);
Public class MyApp extends application{ Private StaticMyApp instance =NULL;Privatelist<activity> activities =NewArraylist<activity> (); Public void addactivity(Activity activity) {Activities.add (activity); } Public void finishactivity() { for(Activity activity:activities) {activity.finish (); } } Public StaticMyAppgetinstance() {if(Instance = =NULL) {instance =NewMYAPP (); }returnInstance }@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 methodFinishactivity ();//language toggle Exit //At the beginning, I was directly using the following method, when the test found that if the app started multiple activity when the implementation of this method will cause the app multiple restarts, and finally with the bulk shutdown activity solved //system.exit (0); //android.os.process.killprocess (Android.os.Process.myPid ()); }}
The app cannot update the solution to the resource file when the Android system switches languages