1

I am new to Handler in Android, I wanna test Handler, so I use ThreadHandler and extends it, at the same time I override the method - run(), adding some log to indicate the start an end of the Looper. but when the test done, I just saw the start log and didn't see any end log, so why the override method run() didn't execute completely?

The code as following:

private void test_ThreadHandler(HandlerThreadTest handlerThreadTest){
       handlerThreadTest.getHandler().post(new Runnable() {
            @Override
            public void run() {
                Log.d(Tag, "handlerThreadTest quit!");
                handlerThreadTest.quitSafely();
            }
        });
}
static class HandlerThreadTest extends android.os.HandlerThread {
        private Handler mHandler;

        public HandlerThreadTest(String name) {
            super(name);
            mHandler = new Handler();
        }

        public HandlerThreadTest(String name, int priority) {
            super(name, priority);
            mHandler = new Handler();
        }

        public Handler getHandler() {
            return mHandler;
        }

        @Override
        public synchronized void run() {
            // I just see this log
            Log.d(Tag, "Looper start!");
            super.run();
            // why I can't see this log ?
            Log.d(Tag, "Looper end!");
        }
    }
Ammar Abdullah
  • 802
  • 4
  • 8
  • 21
Jack_Du
  • 105
  • 7

0 Answers0