Sobes.tech
Junior — Middle

What type of Looper should a Handler use to send data from a background thread to the main thread of the application?

sobes.tech AI

Answer from AI

To send data from a background thread to the main application thread in Android, the Handler must use the Looper of the main (UI) thread. Usually, this is Looper.getMainLooper().

Example of creating a Handler in the main thread:

Handler mainHandler = new Handler(Looper.getMainLooper());

This ensures that messages and Runnables sent through this Handler will be processed in the main thread, which is necessary for updating the UI.

What type of Looper should a Handler use to send data… - sobes.tech