是否有可能分开的WebView UI和HTTP线程? [英] Is it possible to separate WebView's UI and HTTP threads?

查看:248
本文介绍了是否有可能分开的WebView UI和HTTP线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于种种原因,我需要<一个href=\"http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29\">runOnUiThread()实际实例和放大器; 的WebView 的初始化。

For various reasons, I need to runOnUiThread() the actual instantiation & initialization of WebView.

这意味着其潜在的HTTP连接也UI线程做?

Which means that its underlying HTTP connections are also made on the UI thread?

如果这是真的,是有可能的的WebView UI THEAD从HTTP连接线分开?

If this is true, is it possible to separate the WebView's UI thead from the HTTP connections thread?

如果有可能,什么是解决这个问题的正确方法?

If it is possible, what is the proper way of accomplishing this?

推荐答案

我觉得非常很难相信的Andr​​oid将运行在UI线程远程HTTP请求,假设你通过<发起请求code> WebView.loadUrl()。这将使一个糟糕的用户体验。

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.

就很快,我跑在调试Android应用程序,一个基本的的WebView ,并停止在调试器。下面是我所看到的:

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

如果 WebViewCoreThread WebViewWorkerThread http0 - http3 不处理对于的WebView 的对象,那么

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


  1. 他们有非常坏的名字

  2. Android是内置实在太差了

另外,如果你看看这个答案由堆栈溢出的声誉最高的用户,使用loadURL(之一)是异步。在调试器中快人一步,通过告诉我,使用loadURL(),这就是所谓的UI线程(又名 ),完成得太快的连接要在UI线程上同步处理。 (我把一个断点之前调用使用loadURL()与我知道是不是很快送达的URL后)。

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!)

这篇关于是否有可能分开的WebView UI和HTTP线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆