何时使用基于 aidl 的服务?

发布于 2024-09-11 23:23:35 字数 162 浏览 3 评论 0原文

在什么情况下使用 AIDL 定义服务接口是正确的决定(而不是仅仅创建 service 类的扩展)?

Under what circumstances would using AIDL to define a service interface be the correct decision (rather than just creating an extension to the service class)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的他你的她 2024-09-18 23:23:35

如果您希望应用程序进程之外的类访问服务,则需要使用 AIDL。如果您仅从应用程序内部使用该服务,则可以使用 本地服务

You need to use AIDL if you want a class outside of your application's process to access the Service. If you're only using the service from inside your application, you can use a local service.

红玫瑰 2024-09-18 23:23:35

仅扩展服务类将不允许您的服务向外部实体公开其方法。如果您希望您的服务由在 Android 应用程序之外运行的代码公开/使用,则必须为其定义 AIDL。此 AIDL 将被共享并形成为您的服务合同。请参阅此http://developer.android.com/guide/components/aidl.html。

Merely extending a service class will not allow your service to expose its methods to outside entities. If you want your service to be exposed/used by code which runs out of your android app, you will have to define an AIDL for it. This AIDL will be shared and be formed as contract for your service. Refer this http://developer.android.com/guide/components/aidl.html.

不气馁 2024-09-18 23:23:35

1.何时使用基于aidl的服务。

将部分代码分段到后端服务中可以获得一些好处:

  • 前端和后端解耦
  • 内存/CPU密集型处理可以堆叠到后端服务,服务中的GC不会影响前端用户体验
  • 服务崩溃不打倒整个APP

2.如何创建这样一个服务

我已经写了一个很好的库,你可以参考一个例子 http://github.com/zhchang/hogwarts

1.when to use aidl based service.

A few benefits can be gained by segment part of your code into backend service:

  • decouple front-end and back-end
  • memory/cpu intensive processing can be stacked to backend service, GC in service will not affect front-end user experience
  • service crash will not bring down the whole APP

2.how to create such a service

I have written a good library, you can refer as an example http://github.com/zhchang/hogwarts

箜明 2024-09-18 23:23:35

AIDL

Android 接口定义语言 (AIDL) 允许开发人员定义客户端和服务器用于通过进程间通信 (IPC) 相互通信的编程接口。

本文介绍如何连接到 Android 中正在运行的服务,以及如何从远程/正在运行的服务检索数据。

IPC机制示例

设RemoteService为客户端服务,RemoteServiceClient为与远程服务通信的Activity。

一项服务提供有关给定两个整数的数学运算(例如加法、减法和乘法)的信息。要公开服务可以执行的功能,请在项目目录中创建一个 .aidl 文件。

AIDL 示例

AIDL

The Android Interface Definition Language (AIDL) allows developers to define a programming interface that the client and server use to communicate with each other using Inter-Process Communication (IPC).

This article shows how to connect to a running service in Android, and how to retrieve the data from the remote/running service.

Example of IPC mechanism

Let RemoteService be a client service and RemoteServiceClient be an Activity to communicate with the remote service.

One service provides information about the mathematic operations like addition, subtraction, and multiplication for the given two integers. To expose the functionality of what Service can do, create an .aidl file in the project directory.

AIDL Example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文