Skip to content

Instantly share code, notes, and snippets.

@forforf
Created July 25, 2012 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forforf/3177475 to your computer and use it in GitHub Desktop.
Save forforf/3177475 to your computer and use it in GitHub Desktop.
Android - Custom Handler Thread
//Note that this mostly duplicates Android's HandlerThread class
// so that one might be a better choice
// The only thing this one has going for it is that the handler is part
// of the thread instance, but this may not be as flexible.
public class MyHandlerThread extends Thread {
private static final String TAG = "MyThread";
public Handler mHandler;
private static int thrCount = 1;
public MyHandlerThread() {
super(TAG + thrCount);
thrCount += 1;
mHandler = null;
}
public void run() {
Log.d(TAG,"starting");
Log.d(TAG,"Message Handler");
Looper.prepare();
//Handler handler = new Handler();
mHandler = new Handler();
Looper.loop();
Log.d(TAG,"exiting");
}
public void test(){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment