Tag Archives: ui thread

One Way to Cancel an AsyncTask

In AsyncTask, I have had trouble stopping the task. I found that onCancelled gets called immediately, but the real background task can take a bit longer to finish, particularly if it has break out of a loop that has a long-running computation. To address this problem, I changed the way I used publishProgress in the background task. I added an extra argument to indicate the kind of progress information that was being reported, and used one kind of progress inside the loop and another after the loop completed. Continue reading

Posted in Android | Tagged , , , | 2 Comments

Using Android AsyncTask For Background Tasks

My last note (“Long Computations in the Main Android Thread”) explained one way to take an expensive operation and move it to a background task. Since writing that, I have learned about the AsyncTask class. It is much easier way to do the same thing.

If you are looking for a working example of AsyncTask, I have built one and posted the source code at the end of this note.
Continue reading

Posted in Android | Tagged , , , | 9 Comments

Long Computations in the Main Android Thread

In an Android application, you should try very hard to keep your application responsive to user actions (clicks, touches, etc.). That means not doing time-consuming operations like network downloads or long computations in the main thread in which an activity runs. Continue reading

Posted in Android | Tagged , , | 4 Comments