I made thread that send String back to main thread periodically. and I put this thread on some function.
When I press some button, than function will be called and do the work.
The problem is when I press that button twice.
That two threads are sending their String to main thread. (They do the exactly same thing, but different string.)
But I don't need the first thread when thread started again.
Is their any way to kill the first thread?
here's the code.
private void speller_textbox(final String string){
final int strlen = string.length();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
int cursor= 0;
while(cursor != strlen){
try{
Message message = Message.obtain();
message.obj = string.subSequence(0,cursor);
txt_handler.sendMessage(message);
cursor++;
Thread.sleep(100);
}catch (Exception e){
e.printStackTrace();
}
}
}
});
thread.start();
}
txt_handler is on the main thread.