'Android webview request stuck in pending forever
I am showing a programmatically created webview in a bottomsheet fragment. The webview is persisted on a singleton that outlives the fragment The webview is created like so:
webView = WebView(context).let { webView ->
webView.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
webView.clearCache(true)
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.measure(100, 100)
webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true
webView.addJavascriptInterface(AndroidJavascriptInterface(environment), webViewHook)
webView.webViewClient = webViewClient
webView.webChromeClient = webViewChromeClient
webView.loadUrl("file:///android_asset/snippet.html")
webView
}
and then present the webview in a bottomsheet fragment like so:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (webController == null) {
// activity restarted without original context
dismiss()
} else {
webController?.webView?.visibility = View.VISIBLE
webController?.let {
fragment_web_view?.addView(webController?.webView)
}
}
}
I observe these undesirable behaviors: The webview's network requests all get stuck at pending when being backgrounded for around 2 min
- If I persist the webview using a singleton, the webview stops making network request after the webview is presented and then dismissed
- If I never present the fragment, the webview works fine no matter how long I wait
Requests start normal but stays pending after a while
But in these two scenarios the webview works fine.
- If I keep the webview on screen all requests work fine.
- If I keep presenting and dismissing the webview, all requests works fine.
Is there something that I don’t understand about the android webview that may have caused this issue? In order to refresh the webview, I need to reinitialize it to make the requests work again.
Solution 1:[1]
Looks like this is an issue with lates version of WebView. Can you open play market on the device find Android System WebView and try to downgrade it. Form me everything works fine on version 74 and stuck in pending on version 99. Let me know if it works same for you or you already found a reason?

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | anton belichenko |
