Abstract Running Thread : Thread « Development « Android






Abstract Running Thread

    

//package cn.edu.hit.voidmain.asmsreplier.pd_factory.threads;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public abstract class RunningThread extends Thread {
  protected Handler handler;
  
  public void setHandler(Handler handler)
  {
    this.handler = handler;
  }
  
  public Handler getHandler()
  {
    return this.handler;
  }
  
  public abstract void doWork();

  @Override
  public void run() {
    super.run();
    
    doWork();
    
    Message m = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putBoolean("result", true);
    m.setData(b);
    handler.sendMessage(m);
  }

}

   
    
    
    
  








Related examples in the same category

1.Threads Handler Demo
2.Sleep current thread
3.Executors.newFixedThreadPool
4.Counting Thread
5.Task Queue
6.Delay Task