private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_RECEIVED: String message = (String) msg.obj; displayIncomingMessage(message); break; case MESSAGE_SENT: String message = (String) msg.obj; displayOutgoingMessage(message); break; } } }; public void onReceiveMessage(String message) { Message msg = mHandler.obtainMessage(MESSAGE_RECEIVED, message); mHandler.sendMessage(msg); } public void onSendMessage(String message) { Message msg = mHandler.obtainMessage(MESSAGE_SENT, message); mHandler.sendMessage(msg); }In this example, the chat application has a handler that listens for incoming messages and outgoing messages. The onReceiveMessage and onSendMessage methods are called by the chat application when a new message is received or sent, respectively. These methods create a new message object using the handler's obtainMessage method and send the message to the handler using the sendMessage method. The package library for the android.app Activity handleMessage method is android.os.Handler.