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