Code example for HandlerThread

Methods: getLooper, isAlive, setDaemon, start

0
     */ 
    public void startWatching() { 
    	mThreadName = FileWatcher.class.getSimpleName();
		if (mThread == null || !mThread.isAlive()) {
			Log.i(LOG_TAG,"startFileWather new HandlerThread...");
			mThread = new HandlerThread(mThreadName,Process.THREAD_PRIORITY_BACKGROUND);
			mThread.setDaemon(true);
			mThread.start();
 
			mThreadHandler = new Handler(mThread.getLooper());
			mThreadHandler.post(new Runnable() {
				@Override 
				public void run() { 
					Log.i(LOG_TAG,"startWatching mDescriptor:" + mDescriptor);
			        if (mDescriptor < 0) {
			            mDescriptor = s_observerThread.startWatching(mPath, mPath, mMask, FileObserver.this);
			            Log.i(LOG_TAG,"startWatching finished mDescriptor: " + mDescriptor);
			        } 
				} 
			}); 
		}