开发者

A service calling a service, onServiceConnected never called?

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开发者_如何学C'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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜