Whenever I start my thread I always do this check. I did not find anywhere that I called start on thread without doing the check below
if (!myThread.isAlive())
myThread.start();
Nevertheless, I end up with IllegalThreadStateException : Thread already started. This actually crashes my app (android). So is there some other check I need to do before starting up a thread?
You should check if the thread has already started using getState() and start it only if its state is NEW, otherwise create new thread (if needed).
Do you create a new instance for myThread reference using new? You can only perform myThread.start() once on a single instance.
Checking if it is alive is not the right way. Create a new instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With