Talking about WebView in new window (Setsupportmultiplewindows () and Oncreatewindow () relationship)

Source: Internet
Author: User

One, written in front

There are three ways we can use a Computer browser to browse the Web:

1. New Window

2. New tab for current window type

3. Current tab or window

We know that in the computer system can open many of the same process at the same time, as you can log on 2 QQ, while in the phone, the same process can only have one running.

Compared to the browser of the smartphone, such as: QQ browser, Baidu Browser, Computer Browser, the new window is equivalent to re-open a browser, and in the phone, we are using WebView load page, although the browser its application process only one,

However, there can be more than one WebView object in memory. The new window on the phone is creating another webview to load the new page. This relationship makes it possible to browse the Web on a mobile phone in two ways:

1. New tab

2. Current tab

The above is a simple understanding of their relationship, the following cut to the chase

Two, setsupportmultiplewindows and Oncreatwindow

1.setSupportMultipleWindows

We first initialize the webview when we use it.

WebSettings websettings = webview.getsettings (); Settings.setdefaultfontsize (+); Settings.setdefaultfixedfontsize (+); Settings.setsupportmultiplewindows (true) ... Wait

Then look at the target property of the HTML <a> tag:

<a href= "http://www.baidu.com" target= "_blank" > Baidu </a>

Tartget has 4 properties:

_blank

The browser always loads the target document in a newly opened, unnamed window.

_self

The value of this target is the default target for all <a> tags that do not have a target specified, which causes the target document to be loaded and displayed in the same frame or window as the source document. This goal is superfluous and unnecessary unless used with the target property in the document title <base> tag.

_parent

This goal causes the document to be loaded into the parent window or the frameset that contains the frame referenced by the hyperlink. If the reference is in a window or in a top-level frame, then it is equivalent to the target _self.

_top

This goal causes the document to be loaded into the window containing the hyperlink, with the _top target clearing all the contained frames and loading the document into the entire browser window.

We just need to know the _blank property to

What does setsupportmultiplewindows mean by this method?

Setsupportmultiplewindows default is False, that is, WebView does not support the new window, but this is not to say WebView can not open multiple pages, but you click on the page connection, when its target property is _blank. It will continue to load that connection on the page you are currently seeing. Instead of reopening a window.

When you set it to true, it means that you want your webview to support multiple windows, but once set to true, you must override the Webchromeclient Oncreatewindow method.

Here's a look at the signature of this method:

   @Override        publicboolean Boolean boolean isusergesture, Message resultmsg) {                    }

To read the document carefully, you should know the meaning of this parameter:

View : Request a new window for WebView

Isdialog : If true, this new window is just a dialog box, and if it is false, it is a whole size window

isusergesture If true, this request is triggered by a user, such as clicking a connection on a page

resultmsg , when a new WebView is created this is only passed to him, Resultmsg.obj is a Webviewtransport object that is used to transmit to the newly created WebView, using the method:

WebView.WebViewTransport.setWebView (WebView)

Return value: If this method returns True, it will create a new window on behalf of the host application, otherwise it should return Fasle. If you return false, but still sending resulmsg will result in an unknown result.

If we just embed webview into our own app and then load the page, it's rarely necessary to set up support for multiple windows. The new page is loaded only in the current window.

The following is the necessary code to rewrite Oncreatewindow:

Webview.webviewtransport transport = (Webview.webviewtransport) Msg.obj;transport.setwebview (WebView);     // This webview can be a generally newly created       Msg.sendtotarget ();

Talking about WebView in new window (Setsupportmultiplewindows () and Oncreatewindow () relationship)

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.