I have a worker thread that sits in the background, processing messages. Something like this:
class Worker extends Thread {
public volatile Handler hand
take a look at the source code of HandlerThread
@Override
public void run() {
mTid = Process.myTid();
Looper.prepare();
synchronized (this) {
mLooper = Looper.myLooper();
notifyAll();
}
Process.setThreadPriority(mPriority);
onLooperPrepared();
Looper.loop();
mTid = -1;
}
Basically, if you are extending Thread in worker and implementing your own Looper, then your main thread class should extend worker and set your handler there.