有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

IntentService中的java RemoteException

我的IntentService中有以下代码,用于向注册的客户端发送Message

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

根据send()的文档,该方法可以专门抛出一个RemoteException,一个DeadObjectException

DeadObjectException的文档中:

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

如果我理解正确,这意味着如果我的客户都来自Service的流程,(理论上)这个Exception将永远不会被抛出

我说得对吗

提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    是的
    但重要的是要注意Messenger的全部目的是与官方文件中提到的不同流程进行沟通:

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

    如果您需要在同一过程中与您的服务进行通信,我建议使用local bound service