Android Remote Service

2019-08-04 17:58发布

Does running an Android service in a remote process mean that it's running on a different Thread? Is that a difference between a local and remote service?

Similarly, when calling a remote service via IPC, does it return immediately? Or does it wait for action to be done?

3条回答
三岁会撩人
2楼-- · 2019-08-04 18:15

Does running an Android service in a remote process mean that it's running on a different Thread?

Since threads are owned by their process, having a service in a separate process means it will be using threads other than those used by any other process.

Is that a difference between a local and remote service?

Typically, a "remote service" is one supplied by a separate application.

Similarly, when calling a remote service via IPC, does it return immediately? Or does it wait for action to be done?

Calls are synchronous -- they have to be, since AIDL methods can return results. When a client calls a service via an AIDL-defined method, the client blocks until the service returns, regardless of what process or thread either side happens to be using.

查看更多
\"骚年 ilove
3楼-- · 2019-08-04 18:27

Similarly, when calling a remote service via IPC, does it return immediately? Or does it wait for action to be done?

The calls are synchronous as CommonsWare noted, but a common pattern with Remote Services is to use callbacks which allows the Remote Service to asynchronously notify the client.

You can see an example of doing that in the Android docs: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/RemoteService.html

查看更多
手持菜刀,她持情操
4楼-- · 2019-08-04 18:32

Android Services, be default, run in the same thread as Activities etc:

"Note that services, like other application objects, run in the main thread of their hosting process." ref

A local service is one being used by other components within the same application at compile time: they can call upon a service's methods just as you do any other object.

A remote service is one that is being called via AIDL, and a compile time relationship is not required.

查看更多
登录 后发表回答