I’m trying to make use of a background task in my screen controller by executing it whenever a user completes certain tasks on the screen.
If I try and do this more than once, I get this exception thrown: IllegalStateException: Task is already started. I also noticed the background task is staying in the list of threads stuck on WAITING in the Performance Statistics section of the app. I’m assuming this is why the exception is being thrown and can’t seem to figure out how to get the thread to go away once the task is done running. Am I just missing something small?
Edit: I forgot to mention that the done() function in the background task is being called as well after the task is done.
I do have one more question though. Creating a new task every time I want to run the task does create new threads still and leave them there after the task is finished. Is this okay? Would any issues occur if a large number of threads are created? I do know the threads go away eventually and aren’t doing anything once the task is finished but just wondering.