My application contains a long loop which calculates many values within my UIThread and subsequently draws them onscreen.
If I were to offload the calculation loop onto a separate thread using AsyncTask
, I would be unable to run MyAsyncTask.execute() multiple times as according to the documentation: "The task can be executed only once". When I attempted to run the code I was able to see a single frame drawn but then an exception was thrown: "Cannot execute the task: the task has already been executed (a task can be executed only once)".
It would not be a good idea to create a new AsyncTask
object during each iteration of the draw loop, so is there any way to reuse the same AsyncTask object to run MyAsyncTask.execute() again? Or if not, what would be a more appropriate method to use? Can other forms of threads achieve this?