1

I have the following code in my IntentService to send a Message to the registered clients:

for(Messenger client : clients) {
    client.send(aMessage);
}

According to the documentation of send(), this method can throw a RemoteException, a DeadObjectException specifically.

From the documentation of DeadObjectException:

The object you are calling has died, because its hosting process no longer exists.

If i understand correctly, this means that if my clients are all from the Service's process, (theoretically) this Exception will never be thrown.

Am i correct?

Thanks in advance.

justanoob
  • 1,797
  • 11
  • 27

1 Answers1

1

Yes.
But important to note that the whole purpose of Messenger is to communicate with different processes as mentioned in the official documentation:

If you need your service to communicate with remote processes, then you can use a Messenger.

If you need to communicate with your service in the same process I would recommend using local bound service.

Nir Duan
  • 6,164
  • 4
  • 24
  • 38
  • Thanks for your answer. As i understand using Messenger is required if i would like to implement two-way communication. Without using a Messenger i can call methods of my Service, but i cannot call methods of my Activity from the Service. Am i wrong? – justanoob Aug 28 '16 at 09:01
  • You're right again, if you need two way communication you can either use messenger, or (depends on your needs) use binder to communicate with your service and localBroadcastReceiver to notify your activity about new info, look here: http://stackoverflow.com/a/20595215/6028746 – Nir Duan Aug 28 '16 at 09:12