一个服务调用一个服务,onServiceConnected 从未被调用?
我有一个远程服务,它调用一些 jni 来启动 ac 进程。启动进程后,它可以报告要连接的远程活动(通过 AIDL)的端口号。我在另一个 .apk 中有一个服务启动远程服务,然后绑定到它。如果远程服务在 Activity 的服务尝试连接到它之前启动,它将在 Activity 的服务中调用 onServiceConnected 。如果远程 Activity 负责两者启动和绑定,则首先发生绑定,然后紧接着 onStartCommand(),但在这种情况下,永远不会调用 onServiceConnected()。
在我的活动中,只要最终调用 onServiceConnected(),它就与事件的顺序无关。为什么会出现这种情况?
<代码>______________________________________________
澄清一下,远程服务首先启动(好的场景): ______________________________________________
V/rmt_service(11202): onStartCommand Enter
V/rmt_service(11202): onStartCommand 退出
V/rmt_service(11202): onBind 输入
V/rmt_service(11202):端口:50336
V/rmt_service(11202):端口:50943
V/rmt_service(11202):端口:57703
V/rmt_service(11202): onBind 退出
V/act_service(11221): onStartCommand - 输入
V/act_service(11221):bindService - 输入
V/act_service(11221):bindService - 退出
V/act_service(11221): onStartCommand - 退出
V/rmt_service(11202): onStartCommand 输入
V/rmt_service(11202): onStartCommand 退出
V/act_service(11221): onServiceConnected - 输入
V/act_service(11221): onServiceConnected - 退出
V/act_service(11251): onStartCommand - 输入
V/act_service(11251):bindService - 输入
V/act_service(11251):bindService - 退出
V/act_service(11251): onStartCommand - 退出
V/rmt_service(11202): onStartCommand 输入
V/rmt_service(11202): onStartCommand 退出
V/act_service(11251): onBind - 输入
V/act_service(11251): onBind - 退出
V/act_service(11251): onServiceConnected - 输入
V/act_service(11251): onServiceConnected - 退出
________________________________________________________
现在是坏处:______________________________________________
V/act_service(11278): onStartCommand - 输入
V/act_service(11278):bindService - 输入
V/act_service(11278):bindService - 退出
V/act_service(11278): onStartCommand - 退出
V/act_service(11278): onBind - 输入
V/act_service(11278): onBind - 退出
V/rmt_service(11285): onBind 输入
V/act_service(11278): getLib - 输入
V/rmt_service(11285): 端口:58782
V/rmt_service(11285):端口:41039
V/rmt_service(11285):端口:33770
V/rmt_service(11285): onBind 退出
V/rmt_service(11285): onStartCommand 输入
V/rmt_service(11285): onStartCommand exit
您可以看到,即使我在调用 bindService() 之前在远程服务上调用了 startService(),它们系统也会首先绑定到服务,然后调用 onStartCommand()。
任何帮助将不胜感激。
编辑
即使我在调用 startService() 后添加暂停,它也不起作用,bindService(intent, servConn, Context.BIND_AUTO_CREATE); 也不起作用。而不是开始然后绑定。它必须事先运行,然后才能正常连接,这是什么原因?
I have a remote service, it calls some jni to start a c process. After it starts the process it can report the port numbers for a remote activity (via AIDL) to connect to. I have a service in another .apk that starts the remote service, then binds to it. If the remote service is started before the Activity's service tries to connect to it, it will call onServiceConnected in the Activity's service. If the remote Activity is responsible for both starting and binding, the bind happens first, followed shortly by the onStartCommand(), but in this scenario onServiceConnected() is never called.
In my activity it is agnostic to the order of events as long as onServiceConnected() is eventually called. Why does this happen?
______________________________________________
To clarify, Remote service started first (the good scenario):______________________________________________
V/rmt_service(11202): onStartCommand enter
V/rmt_service(11202): onStartCommand exit
V/rmt_service(11202): onBind enter
V/rmt_service(11202): Port:50336
V/rmt_service(11202): Port:50943
V/rmt_service(11202): Port:57703
V/rmt_service(11202): onBind exit
V/act_service(11221): onStartCommand - enter
V/act_service(11221): bindService - enter
V/act_service(11221): bindService - exit
V/act_service(11221): onStartCommand - exit
V/rmt_service(11202): onStartCommand enter
V/rmt_service(11202): onStartCommand exit
V/act_service(11221): onServiceConnected - enter
V/act_service(11221): onServiceConnected - exit
V/act_service(11251): onStartCommand - enter
V/act_service(11251): bindService - enter
V/act_service(11251): bindService - exit
V/act_service(11251): onStartCommand - exit
V/rmt_service(11202): onStartCommand enter
V/rmt_service(11202): onStartCommand exit
V/act_service(11251): onBind - enter
V/act_service(11251): onBind - exit
V/act_service(11251): onServiceConnected - enter
V/act_service(11251): onServiceConnected - exit
______________________________________________
Now the bad:______________________________________________
V/act_service(11278): onStartCommand - enter
V/act_service(11278): bindService - enter
V/act_service(11278): bindService - exit
V/act_service(11278): onStartCommand - exit
V/act_service(11278): onBind - enter
V/act_service(11278): onBind - exit
V/rmt_service(11285): onBind enter
V/act_service(11278): getLib - enter
V/rmt_service(11285): Port:58782
V/rmt_service(11285): Port:41039
V/rmt_service(11285): Port:33770
V/rmt_service(11285): onBind exit
V/rmt_service(11285): onStartCommand enter
V/rmt_service(11285): onStartCommand exit
You can see that, even though I called startService() on the remote service before calling bindService() they system binds to the service first, and then calls onStartCommand().
Any help would be appreciated.
edit
Even if I add a pause after I call startService() it doesn't work, nor does bindService(intent, servConn, Context.BIND_AUTO_CREATE); instead of starting then binding. It has to be previously running, then it connects fine, what gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论