Pause and Resume AsyncTasks? (Android)

Posted by Matt Swanson on Stack Overflow See other posts from Stack Overflow or by Matt Swanson
Published on 2010-03-19T02:12:48Z Indexed on 2010/03/19 2:21 UTC
Read the original article Hit count: 359

Filed under:
|

I have an AsyncTask that acts as a countdown timer for my game. When it completes the countdown it displays the out of time end screen and it also updates the timer displayed on the screen. Everything works fine, except I need to be able to pause and resume this when the pause button in the game is pressed.

If I cancel it and try to re-execute it, it crashes with an IllegalStateException. If I cancel it and instantiate a new AsyncTask in its place the old one begins to run again and the new one runs at the same time.

Is there a way to cancel/pause the timer and restart it using AsyncTasks or is there a different way I should be going about doing this?

© Stack Overflow or respective owner

Related posts about android

Related posts about java