thread = new Thread()
{
@Override
public void run() {
while(!requestedToExit)
{
SystemClock.sleep(3000);
Log.d("debug", "in");
}
}
};
So a button got an event, Each time I click on it it’s start the thread (if the previous thread is not alive).
So I tried use thread.start() but it throw thread already started. I tried .run(), nothing happens, I also tried each time I click on the button, and it’s possible to run it again, create a new thread and start it : nothing.
Some ideas ?
Using Runnable :
r= new Runnable(){
public void run() {
while(!requestedToExit)
{
Log.d("debug", "in");
SystemClock.sleep(3000);
}
}
};
Then I use in my listener :
thread = new Thread(injection);
thread.start();
But I only see the debug the first time, he never enter into it after.
Thanks in advance
From the JavaDoc –
Instead, use
java.lang.Runnableand create a new thread to run it when you have to.What you need to do is:
Then, when you want to start it:
You need to always create a new thread to run that one runnable.