Thursday, May 11, 2023

Daily#5. Android's Message and Handler

 Android's Message and Handler classes are key components of its message passing framework. They're used to schedule and execute code at a future point in time, and on a specific thread.

 A Message represents a command that can be dispatched for processing. A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. 

 Here's a simple example of sending a Message from a background thread to the main thread:
Handler handler = new Handler(Looper.getMainLooper());

Message message = handler.obtainMessage();
// Set what, arg1, arg2, or obj if needed
handler.sendMessage(message);

Remember: Always obtain a Message from a Handler instance. This ensures the Message is correctly associated with the Handler's Looper.

No comments:

Post a Comment

Learning Journey #6: Brief Exploration of Databases and its Management Systems

  Welcome to the "Learning Journey" series. This space is my personal archive where I share insights and discoveries from my explo...