[Crash Repair Solution] WebView in Badtokenexception

Source: Internet
Author: User

1. Background

Paste crash platform, received a large number of webview due to window token failure problem caused by crash.

2.Crash Stack

3.BadTokenException type

4. Causes

In the WebView, can be through the JS and front-end page interaction, in the JS call, there will be a lot of cases in the Native page popup window, such as jsalert,jsprompt,jsconfirm and so on. This crash is caused if the activity is being destroyed, or if the token of the current window is invalidated.

5. Code Analysis

Setwebchromeclient is called in A.webview, Webchromeclient is set to Mprovider

B.mprovider is an example of getting webviewfacotryprovider through Webviewfactoryprovider.

C. Create an instance of Webviewclassic$factory by reflection to return

D. In Webviewclassic's setwebchromeclient, call Callbackproxy.setwebchromeclient

E. In Callbackproxy.handlemessage, it is found that the pop-up event can be intercepted in hook functions such as Mwebchromclient.onjsalert.

6. Solution

Set webchromeclient in WebView, and onjsconfirm and so on will pop up the system alertdialog before the judgment, if the current token is invalid, do not play the window, return true

Judging token invalidation requires judgment:

1. Is the current activity in the finish state

2.Activity token is in alive and in active state

[Crash Repair Solution] WebView in Badtokenexception

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.