Is it possible to separate WebView's UI and HTTP threads?

旧街凉风 提交于 2019-12-01 15:17:19
Nate

I find it very hard to believe that Android would run remote HTTP requests on the UI thread, assuming you initiate the requests via WebView.loadUrl(). This would make for a terrible user experience.

Just quickly, I ran an Android app in the debugger, with a basic WebView, and stopped in the debugger. Here's what I see:

If WebViewCoreThread, WebViewWorkerThread, or http0 - http3 aren't handling the network connections for WebView objects, then

  1. They have very bad names
  2. Android is built really badly

Also, if you look at this answer by one of stack overflow's highest reputation users, loadUrl() is asynchronous. A quick step through in the debugger tells me that loadUrl(), which is called on the UI thread (aka main), completes way too fast for the connection to be handled synchronously on the UI thread. (I put a breakpoint before and after the call to loadUrl() with a URL that I know isn't served very quickly).

So, my answer is you're done ... they're already separate! (yeah!)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!