tags:

views:

50

answers:

1

If an application begins a Service via bindService or startService, will this Service object ever run from a process different from that of the application?

I ask because many Android example projects begin a service and communicate to them using IPC which seems wholly unnecessary considering that, according to the Android Service documentation, "... services, like other application objects, run in the main thread of their hosting process."

IPC, AIDL, and the IBinder interface only seem useful if connecting to a Service started by an application other than your own.

Is this a correct or fair understanding?

A: 

If an application begins a Service via bindService or startService, will this Service object ever run from a process different from that of the application?

Yes, usually if the service is implemented in another application.

I ask because many Android example projects begin a service and communicate to them using IPC

Really?

IPC, AIDL, and the IBinder interface only seem useful if connecting to a Service started by an application other than your own.

IPC and AIDL, yes. Binder, no. You can use that locally too.

CommonsWare
"Really?" Yes, I was surprised as well, because using IPC when you're only ever communicating with your Service from within the same process seemed unnecessary. Being that this is unnecessary, what would you suggest would be the best way to communicate with a Service that is running (and will only ever run) from within the same process?
kpdvx
Well, that varies a bit on how you're going to use it. I have some nice chapters in some books that go into much of the gory details. :-) I'd start with the local binding pattern, per the example project I linked to above. That should work so long as you're not aiming for the service to stay running after all its activities are gone. In that latter case, you'll need to use `startService()` instead of (or perhaps in addition to) `bindService()`. What you definitely *don't* need is AIDL in the local-only case.
CommonsWare