【问题标题】:How to wrap a method around an async section of code如何围绕异步代码部分包装方法
【发布时间】:2020-01-06 01:31:11
【问题描述】:

如何在这段 Async 代码中封装一个方法,以便我可以将变量“doc”作为返回值返回,以便我可以重用这个方法?我不能在这个类中声明一个静态方法,当我尝试使用一个void方法时,无法返回变量“doc”,并且代码中也有错误。

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;
        }

    }

【问题讨论】:

    标签: java class methods jsoup


    【解决方案1】:

    使用

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

    【讨论】:

    • 我应该在里面放什么//在这里使用?我想写一个方法,将参数中的链接传递给Jsoup.connect,然后在方法调用后返回“doc”,这样该方法就可以复用了。
    猜你喜欢
    • 1970-01-01
    • 2018-05-19
    • 2019-05-24
    • 1970-01-01
    • 2011-09-30
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    相关资源
    最近更新 更多