How to wrap a method around an async section of code

北战南征 提交于 2020-01-24 20:52:48

问题


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

    }

回答1:


Use

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


来源:https://stackoverflow.com/questions/59605699/how-to-wrap-a-method-around-an-async-section-of-code

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