码迷,mamicode.com
首页 > 移动开发 > 详细

android学习之remote service 的aidl详解

时间:2015-08-12 01:22:04      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:android   aidl   remote   service   

写在前面的话:

关于remote service中使用aidl来实现跨进程,多线程通信,我是参考了三篇文章,大概把这个弄明白了。
(1)android 官方关于aidl的说明文档
docs/guide/components/aidl.html
(2)Android学习笔记23服务Service之AIDL和远程服务实现进程通信以及进程间传递自定义类型参数
http://blog.csdn.net/honeybaby201314/article/details/19989455
(3) Android AIDL使用详解
http://blog.csdn.net/stonecao/article/details/6425019

aidl的官方描述:

AIDL (Android Interface Definition Language) is similar to other IDLs you might have worked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC).

AIDL(android接口定义语言)与IDLs类似,他主要是定义客户端与服务器统一的编程接口以便让客户端与服务器端跨进程通信(IPC)。

什么地方使用aidl:

Note: Using AIDL is necessary only if you allow clients from different applications to access your service for IPC and want to handle multithreading in your service. If you do not need to perform concurrent IPC across different applications, you should create your interface by implementing a Binder or, if you want to perform IPC, but do not need to handle multithreading, implement your interface using a Messenger.

如果clients要从不同应用跨进程访问service,在service中处理多线程操作。我们才会使用AIDL。如果不需要跨进程,我们可以创建实现Binder的接口,如果我们需要跨进程通信,但是不需要处理多线程操作,那么,我们可以使用Messager.

如何使用aidl:

To create a bounded service using AIDL, follow these steps:

1. Create the .aidl file

This file defines the programming interface with method signatures.

2. Implement the interface

The Android SDK tools generate an interface in the Java programming language, based on your .aidl file. This interface has an inner abstract class named Stub that extends Binder and implements methods from your AIDL interface. You must extend the Stub class and implement the methods.

3. Expose the interface to clients

Implement a Service and override onBind() to return your implementation of the Stub class.

aidl使用的详细步骤

我以官方文档和另外一个样例,写了一个Demo来说明如何实现aidl的使用。
(1)客户端

(2)服务端

版权声明:本文为博主原创文章,未经博主允许不得转载。

android学习之remote service 的aidl详解

标签:android   aidl   remote   service   

原文地址:http://blog.csdn.net/hfreeman2008/article/details/47431123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!