I am creating a game where the user interacts with the GUI while the computer finds solutions to the puzzle in a background task. The user can choose to end the game any time, at which point I want to stop my background task and retrieve the solutions it found.
This is all working fine except that I can't force the background task to end when the user chooses?!? When the user selects "Done" I have the following:
computerSolutionTask.cancel(true);
// ...disable some GUI buttons etc...
while (computerSolutionTask.getStatus() != AsyncTask.Status.FINISHED){
// ...do nothing...
}
txt_computer.setText(computerSolutionTask.get());
And in my AsyncTask class I am checking "isCancelled()" regularly but it just seems to hang in the while loop I included above.
I feel that I may be going about this whole thing a little incorrectly because I don't really want to cancel the background task I just want it to finish wherever it's up to and return what it has.
This thread appears to be asking the same question I am but has no solution...I'm drawing blanks with all my research thus far and any help would be much appreciated.