Skip to content Skip to sidebar Skip to footer

Android: Asynctask, Onpostexecute Starts Before Doinbackground Has Finished

I had this problem a few hours ago (Android: AsyncTask, my 1st task has not finished when the other starts) I put it as solved but then I realized I had a similar problem. Here is

Solution 1:

So the problem is you are timing future runnables for future execution, and then returning from the doInBackground - which immidiatly activates your onPostExecute function.

a solution to your problem is not to use the onPostExcute but instead to time another Runnable with the code you want to run after all the others, since they all run on the same thread this should solve your problem.

Solution 2:

Try this small change, it might help you.

Runnablerunnable=newRunnable() {
                @Overridepublicvoidrun() {
                    image3.setImageResource(drawables[j]);
                     Log.w("GAMEACTIVITY","image"+j);
            gameactivity.handler.postDelayed(this, 200*j);
                }
            };
          gameactivity.handler.postDelayed(runnable, 10);

Post a Comment for "Android: Asynctask, Onpostexecute Starts Before Doinbackground Has Finished"