In-depth explanation of Android Browser configuration management

Source: Internet
Author: User

Settings is an interface provided by WebView to the upper-layer App for configuring Webview. Each WebView has a WebSettings. To control WebView behaviors, you can only use WebView. getSettings () gets the reference of the WebSettings object, and then changes its attributes.
Browser has a BrowserSettings to manage all the configuration information, which is a single key (Singleton ). BrowserSettings directly manages WebSettings, while the UI is completed by BrowserPreferencePage and Fragment. BrowserSettings implements OnSharedPreferenceChangedListener. When a configuration item changes, the BrowserSettings interface onPreferencesChanged will be called back, And BrowserSettings will apply the configuration to WebView through WebSettings, these Settings take effect immediately.

There are three types of Settings: Shared Settings, static Settings, and dynamic Settings.Static configurations that cannot be changed in Browser Settings are not changed when the Browser is running. These configurations are more related to the application, such as the data storage location of the application, there is not much relationship with the user layer; shared Settings are independent of WebView, that is, they are shared by all WebView configurations in the system, such as cookies, which do not need to be configured separately for each WebView. Dynamic Settings are used to dynamically configure WebView, such as font, zoom, image loading, and JavaScript.

Initialization
Because Browser can have multiple windows, each window will have a WebView, that is, Browser will manage multiple webviews, so BrowserSettings also needs to manage multiple WebSettings, because every configuration change must be applied to all webviews. To allow BrowserSettings to manage multiple WebSettings, it must hold references to these WebSettings. When creating a WebView, Browser puts WebView configuration WebSettings in BrowserSettings through the interface. BrowserSettings has a list to hold references to WebSettings. The initWebViewSettings () method in the BrowserWebViewFactory is called after a WebView is created each time. It extracts the WebSettings of the WebView and initializes the WebView to BrowserSettings. startManagingSettings () will load information in the SharedPreference file to initialize this WebSettings and put it in the mManagedSettings list.

Configuration change
The user enters the Settings interface and changes the configuration. Each time the configuration changes, BrowserSettings. onSharedPreferencesChanged () will be called back, And it will perform the syncManagedSettings () Action to synchronize the sharing settings to the underlying layer (that is, synchronize the settings to Cookiemanager ), traverse the mManagedSettings list and synchronize all the information in mPref to each WebSettings. In this way, all webviews will respond to configuration changes in real time.

The configured interface is not directly associated with BrowserSettings. The interface presents various Settings to users through PreferenceActivity and Fragment, while BrowserSettings synchronizes configuration information to WebView, that is, to make the configuration take effect. The information bridge between them is SharedPreference. That is to say, PreferenceActivity and Fragment receive configuration information from the user and put it in SharedPreference. BrowserSettings listens to SharedPreference changes, and then synchronizes 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.