How to check if an Android Thread is running

Assuming that rt is a Thread, just check rt.isAlive().

Alternatively, just use a boolean flag and set it to true right before you start your thread.

I would actually prefer the boolean approach so there is no way that the main thread could start the other thread twice - there may be a short delay until your Thread is up and running, and if your main thread tries to start the thread twice in quick succession, it may get a "false" negative on rt.isAlive().


I've used this approach with success:

if ( mythread.getState() == Thead.State.NEW )
    //then we have a brand new thread not started yet, lets start it
    mythread.start();
else
    //it is running already compensate