Returning data from AsyncTask without blocking UI

前端 未结 3 1535
逝去的感伤
逝去的感伤 2021-02-05 12:32

I have a conceptual problem related to AsyncTask class. We use AsyncTask so that the main UI is not blocked. But suppose, I want to retrieve some data

3条回答
  •  庸人自扰
    2021-02-05 12:43

    You don't get the result this way. See this link for an example : https://github.com/levinotik/ReusableAsyncTask/tree/master/src/com/example

    Basically, here is what you need to do :

    • Define an interface (= a listener) that your activity implements
    • Set the listener in the asynctask
    • Call yourListener.yourMethod() in the onPostExecute

提交回复
热议问题