justanoob justanoob - 3 months ago 19
Android Question

RemoteException in IntentService

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.

Answer

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.