Kill thread when it called twice
<p>I made thread that send String back to main thread periodically.
and I put this thread on some function.</p>

<p>When I press some button, than function will be called and do the work.</p>

<p>The problem is when I press that button twice.</p>

<p>That two threads are sending their String to main thread.
(They do the exactly same thing, but different string.)</p>

<p>But I don't need the first thread when thread started again.</p>

<p>Is their any way to kill the first thread?</p>

<p>here's the code.</p>

<pre><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();
}
</code></pre>

<p>txt_handler is on the main thread.</p>