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.

1
  • will also occur regardless of same process if the service itself stopped but the process is running. Commented Aug 28, 2016 at 8:08

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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: stackoverflow.com/a/20595215/6028746

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.