(1) What is HandlerThread and what HandlerThread can do
1) When the system has multiple time-consuming tasks to be executed, each task will open a new thread to execute the time-consuming task, which will cause the system to create and destroy threads multiple times, thus affecting performance.
HandlerThread was created to solve this problem.
HandlerThread creates a Looper looper in the thread and lets Looper poll the message queue. When a time-consuming task enters the queue, there is no need to open a new thread, and the time-consuming task can be executed in the original thread, otherwise the thread is blocked.
2) Features: The essence is thread, because Thread is inherited.
HandlerThread can execute asynchronous methods in handlerMessage of Handler.
HandlerThread is different from the thread pool. HandlerThread is a string queue with only one thread behind it.
3) Advantages and disadvantages: Advantages: Asynchronous will not block, reducing performance consumption.
Disadvantages: Multitasking cannot be continued at the same time, waiting for processing, and processing efficiency is low.
(2) The essence of HandlerThread: In fact, it is a thread, that is, the Thread class has a built-in encapsulation of a Looper