Notes on Android (java) thread processing

Introduction

There are many thread processing methods in the Android implementation, so I investigated it. I have briefly summarized each concept.

Difference between Thread and Runnnable

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)

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. android-thread-looper-handler.png

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

Notes on Android (java) thread processing
Java thread processing
[Android] Notes on xml
Run node.js from android java (processing)
java notes
Notes on signal control in Java
Notes on calling Installer on Android App
Notes on Java path and Package
Asynchronous processing by RxJava (RxAndroid) on Android
Calling java from C ++ on Android NDK
Notes on operators using Java ~ String type ~
Notes on creating android plugins for Unity
About UI thread processing in Android asynchronous
Java Generics (Notes)
[Android] Detailed notes
Java string processing
[Java] Study notes
Java serialization notes
[Java] Multi-thread processing
[Java] Stream processing
java iterative processing
Try using Firebase Cloud Functions on Android (Java)
Notes on getting Callback from Android text-to-speech function TextToSpeech
Try communication using gRPC on Android + Java server
[Java] 4 steps to implement splash screen on Android
Upload and download notes in java on S3
Notes on Protocol Buffers
[Java] Stream Collectors notes
Java formatted output [Notes]
Install Java on Mac
[Java] Thread and Runnable
python notes on docker
Run PostgreSQL on Java
[Java] Control syntax notes
Ruby Thread # [] = method notes
[Android / Kotlin] Detailed notes 2
Java NIO 2 review notes
Notes on regular expressions
Thread safe summary ~ Java ~
Try image classification using TensorFlow Lite on Android (JAVA)
JAVA constructor call processing
Notes in Android studio
Java random, various processing
Run Processing on Ant
[Java] Basic method notes
Notes on how to use regular expressions in Java
Java Programming Thread Runnable
Java version control on macOS
Customize list view on Android
Multipart transmission library on Android
[Java] New Thread generation method (2)
[Java] Multi-thread processing --Exclusive control
Downgrade Java on openSUSE Linux
Try scraping using java [Notes]
Use serial communication on Android
Reflection on Java string manipulation
On passing Java Gold SE 8
Oracle Java 8 on Docker Ubuntu
[Implementation] Java Process class notes
Java Collections Framework Review Notes
Use serial communication on Android
Try communication using gRPC on Android + Java server
[Android] Notes on xml