Android language switching process analysis

Source: Internet
Author: User
Tags locale

Android language switching process Analysis2014-02-27 18:13 1207 People read comments (0) favorite reports Language switch Android language switch Android Change language

Recently in a bug, the system switch language, the original back to the background of the music, will be displayed on the Notification bar notification. To solve this bug, I learned the language switching process for Android, and also referenced a lot of other people's data. (The main reference is http://blog.csdn.net/wqhjfree/article/details/8244520) Here I recorded my own explorations, as my learning record, but also hope to have the same needs of people have a help. Just learn Android soon, if there is any problem in the middle of the understanding, and point out the wrong, more exchanges, common progress.

1. Starting with setting, we can see that in setting, the entrance to the language setting is inside a class called Localepicker, and the onlocaleselected (final Locale locale) method is invoked when a language is clicked. By analyzing this method, we can know that the last switching language is not done here, but instead calls the Updatelocale () method under Fromwork (located in Frameworks/base/core/java/com/android/ Internal/app/localepicker).


2. Actually he is calling the Fromwork under the Localepicker class in the Updatelocale () method, and we continue to look down. Through analysis, we know that this method is not a final processing method, but to call the Updateconfiguration () function in Activitymanagerservice.java.

3. Look at what the Updateconfiguration () method did, and here are some worthwhile judgments and initial work done. The most important thing is that he invokes the updateconfigurationlocked (values, NULL, FALSE, False) method;

There are two main things that are done in 4.updateConfigurationLocked: (1) Change the current configuration (this is a system-configured class that is interesting to understand) ; (2) Ensure that all running activity runs the changed configuration. Let's see how he did the two things. First, by Updatefrom (values) to determine whether the language has changed, if the change, from the IF condition, in the IF, the front to do some judgments and other work, to this also completed the first step of the work. The most important thing is that the for-loop operation, first to get all the running app collection, and then to each app call Scheduleconfigurationchanged () method, for language switching work.

5.scheduleConfigurationChanged is in Activitythread, this party executes the Updatependingconfiguration (config) and queueorsendmessage (H. configuration_changed, config) two methods. The previous method is to update the Configuration; The primary operation is the handleconfigurationchanged (configuration) msg.obj, NULL, in Queueorsendmessage () Method.

6. Then the analysis of the handleconfigurationchanged, from which we are not difficult to find applyconfigurationtoresourceslocked () This is a reconfiguration of the resources of the function, Performconfigurationchanged (Callbacks.get (i), config) This method is to perform a configuration change. That is, the final completion of the language switch.

7. In a detailed analysis of what applyconfigurationtoresourceslocked does, Updatefrom (config) updates config to the configuration, and the main thing behind it is the while () Resources are updated and deleted in the operation of the resource.

8.performConfigurationChanged method, this is the final step to complete the language switch, first of all to determine whether the current activity of the config and the new config is the same, if it is the same as nothing to do, if not the same, restart the app, Reload the resource to reach the switching language.

9. Summarize the general process of language switching is to determine whether the local language in the configuration changes, if there is a change is to switch languages. When the switching language is executed, the whole system's language switch is completed for those programs that have already run, and the process of clearing and reloading a resource.

Finally, the bug will be solved, after music run, switch language, he destroyed once, and restarted, resulting in the status bar notification prompt.

Android language switching process analysis

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.