VERSUS Messenger handler for Android messaging

Question:

Is it “better” (= faster and less overhead) to use Handler to exchange handlers compared to using Messenger for messaging in Android?

Situation:

An Android application in which there are many actions and one start of a service (initial service). Inside a service, multiple threads run next to the main service thread. The application starts, the first action starts the service, the start starts, the first activity goes to the second action, the second activity is attached to the service, ...

Handler handler:

... the service passes a link to the service handler , the second action defines its own handler, the second activity can now directly communicate with the service directly using the service handler. In order for the service handler to know that it should respond to the activity handler, the msg.obj field in the Message object can be used to set the "reply-to" handler (= handler inside the action). Now, two-way communication is successfully established between actions and the service.

Messenger for the messenger:

... , , , , ( ) Parcelable object, Parcelable ( ) Message, . - , , msg.replyTo . .

"":

Messenger Messenger, , ? ( , ). , Message, , - , " Android".

:

, , , ServiceConnection onServiceConnected() , - , , , , , ( ), . , ( ) msg.obj, , . .

: ui-thread/main-thread, ui-thread/main-thread, , . ?

, Messenger - () ! , Android , Parcelable, ( / . , , , , ).

, :

  • ( Intent!)
  • Messengers ( Handlers , : )
  • ( , , , , Messengers).

, - , , - . ???

, , :) .

+4
1

,

.

> (LocalBroadcastManager, Square Otto, greenrobot EventBus). , Handler, Messenger .

, , , , OnClickListener . , ( ) .

ResultReceiver, , .

+9