In-depth details of Android browser configuration management _android

Source: Internet
Author: User
Settings is a configuration WebView interface that WebView provides to the top app, and each webview has a websettings that controls WebView behavior only through Webview.getsettings () Gets a reference to the WebSettings object, and then changes its properties.
Browser has a browsersettings for managing all configuration information, which is a single bond (Singleton). Browsersettings is the direct management of WebSettings, while the UI part is done by browserpreferencepage and fragment. Browsersettings implements Onsharedpreferencechangedlistener, when a configuration item changes, the Browsersettings interface onpreferenceschanged is recalled to, Then Browsersettings will apply the configuration through the websettings to the WebView, so these settings are in effect in time.

There are three types of settings: shared settings, static settings, and dynamic settings. Static is not a change in the browser runtime, that is, some configurations that cannot be changed in the settings of browser, which are associated with more internal applications, such as the location of the application's data store, and are not much related to the user layer ; shared settings is independent of webview, which means that it is shared by all webview in the system, such as cookies, and it does not need to be configured individually for each webview. Dynamic settings are used to dynamically configure WebView, such as fonts, scaling, whether to load pictures, whether JavaScript is enabled, and so on.

Initialization
Because browser can have more than one window, each window will have a webview, that is to say browser will manage multiple webview, so browsersettings also manage multiple websettings, Because every configuration change is applied to all webview. In order for Browsersettings to be able to manage multiple websettings, it must hold a reference to those websettings. When browser creates WebView, it puts WebView's configuration websettings through the interface into Browsersettings, which has a list that holds references to browsersettings. The Initwebviewsettings () method in the specific browserwebviewfactory is invoked after each creation of the WebView, which takes the websettings of WebView out and makes the necessary initialization. and put it in the Browsersettings, Browsersettings.startmanagingsettings () will load the information in the Sharedpreference file to initialize the websettings. and put it in the Mmanagedsettings list.

Configuration changes
The user enters the settings interface, makes configuration changes, whenever a configuration changes browsersettings.onsharedpreferenceschanged () will be recalled to, it will do syncmanagedsettings () action , the shared settings sync to the bottom layer (also that is, the settings synchronized to the Cookiemanager), and then traverse the list mmanagedsettings, the mpref in all the information synchronized to each websettings, All WebView will respond to configuration changes in real time.

The interface is not directly related to the browsersettings, and the interface is presented to the user through the preferenceactivity and fragment settings, The browsersettings is to synchronize the configuration information to WebView is to let the configuration take effect. The information bridge between them is sharedpreference, that is, preferenceactivity and fragment receive configuration information from the user and then put them in sharedpreference, Browsersettings Monitor sharedpreference changes, and then synchronize Sharedpreference to WebView.
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.