
我有一个使用Jsoup和AsyncTask的工作示例,并且工作正常.我对表现不满意.加载带有文本和图像的简单列表页面需要3-6秒.
我想以某种方式提升表现……所以我偶然发现了凌空抽射.
任何人都可以解释热与Jsoup使用齐射?
我用它来获取包含特定URL的doc对象:
public document Getdocument(String site) { document doc = Jsoup.connect(site).timeout(600000) .data("query", "Java") .userAgent("Mozilla") .get(); return doc; }我想我只会用Jsoup和连接/下载与volley分析数据?我使用Jsoup.connect(site).timeout(600000)我应该用齐射吗?
任何人都可以使用volley和Jsoup编写/链接一个简单的例子吗?
解决方法:
Can anyone write/link a simple example using volley and Jsoup?
在引擎盖下,Jsoup使用httpUrlConnection.此类已知AndroID平台上尚未解决的问题,错误和性能问题.
相反,首先使用Volley加载数据,然后使用Jsoup解析它.
示例代码:
private static RequestQueue myRequestQueue = null;public document Getdocument(String site) throws Exception { final document[] doc = new document[1]; final CountDownLatch cdl = new CountDownLatch(1); StringRequest documentRequest = new StringRequest( // Request.Method.GET, // site, // new Response.Listener<String>() { @OverrIDe public voID onResponse(String response) { doc[0] = Jsoup.parse(response); cdl.countDown(); } }, // new Response.ErrorListener() { @OverrIDe public voID one rrorResponse(VolleyError error) { // Error handling System.out.println("Houston we have a problem ... !"); error.printstacktrace(); } } // ); if (myRequestQueue == null) { myRequestQueue = Volley.newRequestQueue(this); } // Add the request to the queue... myRequestQueue.add(documentRequest); // ... and wait for the document. // NOTE: Be aware of user experIEnce here. We don't want to freeze the app... cdl.await(); return doc[0];}参考
> An Introduction to Volley
> Transmitting Network Data Using Volley
以上是内存溢出为你收集整理的android – 如何使用Jsoup与Volley?全部内容,希望文章能够帮你解决android – 如何使用Jsoup与Volley?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)