The app cannot update the solution to the resource file when the Android system switches languages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.