There are many thread processing methods in the Android implementation, so I investigated it. I have briefly summarized each concept.
Thead and Runnable are features provided by Java To create a method that runs on a thread, you need to _ let the class you want to thread inherit the Thread class_.
However, if there is a class that already inherits another class, the Thead class cannot be inherited. So instead use Runnable as implements.
Handler (and Looper) is a function provided by Android to communicate between threads (not a thread function). The Android UI crashes with an exception when accessed from a thread other than the main thread. Handler can be used to bridge from another thread to the main thread.
Looper is required in addition to Handler to bridge from another thread to another thread. You don't need a Looper to bridge to the main thread, because the main thread already has a Looper internally.
HandlerTask HandlerTask is a class that extends Thead of Java, a function provided by Android. Looper is automatically prepared at the time of generation. Data can be exchanged between threads using Handler.
AsyncTask AsyncTask is a feature provided by Android You can process the UI in another task. The biggest feature is that "processing in the main thread is possible even during asynchronous processing" (that you do not have to use Handler) However, only processing that can be completed in a short time can be used.
Reference: [Thread, Looper, Handler that masters Android background] 1
Recommended Posts