Android in-app language switch implementation (GO)

Source: Internet
Author: User

Using the Java reflection mechanism

Iactivitymanager and Activitymanagernative are non-public classes that use Java reflection to invoke methods in them.

The first step is to use the Android open API to change the configuration while saving the language type

Second step, destroy the current page, redraw to change language type

If your page is not the homepage, your call to the above code will only update the current page, and the activity on the stack will not update the interface. such as setting language success, will automatically jump to the homepage, of course, the content of the homepage is also updated, and its implementation is very simple, and we write the same. Is the listening settings successfully, destroy all existing pages, and then jump to the home page. Your app will be able to meet the above requirements, but don't worry about the third step.

The third step, as long as your app is not completely removed from Dalvik or art, is no problem. However, if you reboot, or force the app to kill, it starts again and reverts to the previous language type.

This will let us use the type of language saved in the first step, in the base class baseactivity of all pages, each time the method of the language setting is invoked, so that the page is forced to set the language type of the business requirement. OK, this problem is solved satisfactorily, to add this function for your app, the code changes are very small.

Android in-app language switch implementation (GO)

Related Article

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.