onPostExecute not called after completion AsyncTask

前端 未结 8 1725
[愿得一人]
[愿得一人] 2020-12-10 09:56

For some reason my onPostExecute() is not called after my AsyncTask finishes.

My class decleration:

public class setWallpaper

相关标签:
8条回答
  • 2020-12-10 10:35

    After having the same problem and none of these answers helped me, I found out that my UI thread was blocked (I used a CountDownLatch.await()) and therefore the onPostExecute() method that is supposed to be called by the UI thread was never called.

    0 讨论(0)
  • 2020-12-10 10:39

    Did you start the task with execute() method? The onPostExecute wouldn't run if you just invoke the doInBackground.

    0 讨论(0)
  • 2020-12-10 10:41

    I had the same behaviour, and the cause was that I have been posting a lot of messages as a progress inside doInBackground with following code:

    new Handler(Looper.getMainLooper()).post(new Runnable() {
       @Override
       public void run() {
         // .. some UI updates
       }
    });
    

    this must have overloaded main thrad message queue, and caused long delay before onPostExecute would get called. The solution was to post only once every second.

    0 讨论(0)
  • 2020-12-10 10:43

    For me it was user error. I was ending the AsyncTask by invoking cancel(true) on it and not reading the documentation closely enough to know that onPostExecute is not called in this case, onCancelled is.

    0 讨论(0)
  • 2020-12-10 10:45

    Found/Made another nasty mistake:

    If your params of onPostExecute(Param param) don't match the one you defined with extends AsyncTask<...,...,Param> and you didn't use the @Override annotation, it will never be executed and you don't get a warning from Eclipse.

    Note to myself: Just always use the @Override annotation and Eclipse will help you.

    Another easy way to avoid all named mistakes:

    in Eclipse: Right-click in code > Source > Override/Implement Methods

    0 讨论(0)
  • 2020-12-10 10:50

    Did you create your AsyncTask on the UI thread? Also add an @Override annotaiton on your onPostExecute() method to make sure you declared it correctly.

    0 讨论(0)
提交回复
热议问题