如何在代码的异步部分中包装方法 [英] How to wrap a method around an async section of code

查看:67
本文介绍了如何在代码的异步部分中包装方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何围绕该代码的Async部分包装一个方法,以便可以获取作为返回值返回的变量"doc",从而可以重用此方法?我无法在此类内声明静态方法,并且当我尝试使用void方法时,无法返回变量"doc",并且代码中也存在错误.

How do I wrap a method around this Async section of codes so I can get the variable "doc" returned as a returned value so I can reuse this method? I can't declare a static method inside this class, and when I tried to use a void method, the variable "doc" can't be returned, and there's also errors in the code.

class JsoupParseTask extends AsyncTask<String, Void, Document> {

        protected Document doInBackground(String... urls) {

            Document doc = null;
            try {
                doc = Jsoup.connect("https://jsoup.org//").get();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }

            return doc;
        }

    }

推荐答案

使用

 protected void onPostExecute(Document 
   result) {
        // Use here
    }

这篇关于如何在代码的异步部分中包装方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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