- 浏览: 116979 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
liubang201010:
可看看此文:http://www.goodu.info/gc/ ...
基于Android手机开发平台的移动数字图书馆服务系统研究 -
chenhaodejia:
hbxflihua 写道你好,在加载xml的时候能不能像htm ...
android自定义Spinner下拉菜单样式并获得选项的值 -
chenhaodejia:
心灵花园2010 写道你好,问下服务端该怎么去搭建?
什么意思 ...
基于Android手机开发平台的移动数字图书馆服务系统研究 -
心灵花园2010:
你好,问下服务端该怎么去搭建?
基于Android手机开发平台的移动数字图书馆服务系统研究 -
hbxflihua:
你好,在加载xml的时候能不能像html页面的select标签 ...
android自定义Spinner下拉菜单样式并获得选项的值
On Android, one process cannot normally access thememory of another process.
You must define your AIDL interface in an
.
aidl
file using the Javaprogramming language syntax, then save it in the source code (in the
src/
directory) of boththe application hosting the service and any other application that binds to the service.
When you build each application that contains the .aidl file, the Android SDK toolsgenerate an IBinder interface based on the .aidl file and save it inthe project's gen/ directory. The service must implement the IBinderinterface as appropriate. The client applications can then bind to the service and call methods fromthe IBinder to perform IPC.
To create a bounded service using AIDL, follow these steps:
1. Create the .aidl file
2. Implement the interface
3. Expose the interface to clients
Caution: Any changes that you make to your AIDL interface afteryour first release must remain backward compatible in order to avoid breaking other applicationsthat use your service. That is, because your .aidl file must be copied to other applicationsin order for them to access your service's interface, you must maintain support for the originalinterface.
1. Create the .aidl file
Each .aidl file must define a single interface and requires only the interface declaration and method signatures.
By default, AIDL supports the following data types:
● All primitive types in the Java programming language (such as int, long,char, boolean, and so on)
● String
● List
● Map
You must include an import statement for each additional type not listed above, even ifthey are defined in the same package as your interface.
When defining your service interface, be aware that:
● Methods can take zero or more parameters, and return a value or void.
● All non-primitive parameters require a directional tag indicating which way the data goes.Either in, out, or inout (see the example below).
● Primitives are in by default, and cannot be otherwise.
● All code comments included in the .aidl file are included in the generated IBinder interface (except for comments before the import and packagestatements).
● Only methods are supported; you cannot expose static fields in AIDL.
Simply save your .aidl file in your project's src/ directory and when youbuild your application, the SDK tools generate the IBinder interface file in yourproject's gen/ directory. The generated file name matches the .aidl file name, butwith a .java extension (for example, IRemoteService.aidl results in IRemoteService.java).
2. Implement the interface
When you build your application, the Android SDK tools generate a .java interface filenamed after your .aidl file. The generated interface includes a subclass named Stubthat is an abstract implementation of its parent interface (for example, YourInterface.Stub) and declares all the methods from the .aidl file.
Note: Stub also defines a few helper methods, most notably asInterface(), which takes an IBinder (usually the one passed to a client's onServiceConnected() callback method) and returns an instance of the stub interface. See the section Calling an IPCMethod for more details on how to make this cast.
There are a few rules you should be aware of when implementing your AIDL interface:
● Incoming calls are not guaranteed to be executed on the main thread, so you need to think about multithreading from the start and properly build your service to be thread-safe.
● By default, RPC calls are synchronous. If you know that the service takes more than a few milliseconds to complete a request, you should not call it from the activity's main thread, because it might hang the application (Android might display an "Application is Not Responding" dialog)—you should usually call them from a separate thread in the client.
● No exceptions that you throw are sent back to the caller.
3. Expose the interface to clients
Once you've implemented the interface for your service, you need to expose it
To clients so they can bind to it. To expose the interface for your service, extend Service and implement onBind() to return an instance of your class that implements the generated Stub (as discussed in the previous section). Here's an example service that exposes the IRemoteService example interface to clients.
Now, when a client (such as an activity) calls bindService() to connect to this service, the client's onServiceConnected() callback receives the mBinder instance returned by the service's onBind()method.
The client must also have access to the interface class, so if the client and service are in separate applications, then the client's application must have a copy of the .aidl file in its src/ directory (which generates the android.os.Binder interface—providing the client access to the AIDL methods).
When the client receives the IBinder in the onServiceConnected() callback, it must callYourServiceInterface.Stub.asInterface(service) to cast the returned parameter to YourServiceInterface type. For example:
You must define your AIDL interface in an
.
aidl
file using the Javaprogramming language syntax, then save it in the source code (in the
src/
directory) of boththe application hosting the service and any other application that binds to the service.
When you build each application that contains the .aidl file, the Android SDK toolsgenerate an IBinder interface based on the .aidl file and save it inthe project's gen/ directory. The service must implement the IBinderinterface as appropriate. The client applications can then bind to the service and call methods fromthe IBinder to perform IPC.
To create a bounded service using AIDL, follow these steps:
1. Create the .aidl file
2. Implement the interface
3. Expose the interface to clients
Caution: Any changes that you make to your AIDL interface afteryour first release must remain backward compatible in order to avoid breaking other applicationsthat use your service. That is, because your .aidl file must be copied to other applicationsin order for them to access your service's interface, you must maintain support for the originalinterface.
1. Create the .aidl file
Each .aidl file must define a single interface and requires only the interface declaration and method signatures.
By default, AIDL supports the following data types:
● All primitive types in the Java programming language (such as int, long,char, boolean, and so on)
● String
● List
● Map
You must include an import statement for each additional type not listed above, even ifthey are defined in the same package as your interface.
When defining your service interface, be aware that:
● Methods can take zero or more parameters, and return a value or void.
● All non-primitive parameters require a directional tag indicating which way the data goes.Either in, out, or inout (see the example below).
● Primitives are in by default, and cannot be otherwise.
● All code comments included in the .aidl file are included in the generated IBinder interface (except for comments before the import and packagestatements).
● Only methods are supported; you cannot expose static fields in AIDL.
Simply save your .aidl file in your project's src/ directory and when youbuild your application, the SDK tools generate the IBinder interface file in yourproject's gen/ directory. The generated file name matches the .aidl file name, butwith a .java extension (for example, IRemoteService.aidl results in IRemoteService.java).
2. Implement the interface
When you build your application, the Android SDK tools generate a .java interface filenamed after your .aidl file. The generated interface includes a subclass named Stubthat is an abstract implementation of its parent interface (for example, YourInterface.Stub) and declares all the methods from the .aidl file.
Note: Stub also defines a few helper methods, most notably asInterface(), which takes an IBinder (usually the one passed to a client's onServiceConnected() callback method) and returns an instance of the stub interface. See the section Calling an IPCMethod for more details on how to make this cast.
There are a few rules you should be aware of when implementing your AIDL interface:
● Incoming calls are not guaranteed to be executed on the main thread, so you need to think about multithreading from the start and properly build your service to be thread-safe.
● By default, RPC calls are synchronous. If you know that the service takes more than a few milliseconds to complete a request, you should not call it from the activity's main thread, because it might hang the application (Android might display an "Application is Not Responding" dialog)—you should usually call them from a separate thread in the client.
● No exceptions that you throw are sent back to the caller.
3. Expose the interface to clients
Once you've implemented the interface for your service, you need to expose it
To clients so they can bind to it. To expose the interface for your service, extend Service and implement onBind() to return an instance of your class that implements the generated Stub (as discussed in the previous section). Here's an example service that exposes the IRemoteService example interface to clients.
Now, when a client (such as an activity) calls bindService() to connect to this service, the client's onServiceConnected() callback receives the mBinder instance returned by the service's onBind()method.
The client must also have access to the interface class, so if the client and service are in separate applications, then the client's application must have a copy of the .aidl file in its src/ directory (which generates the android.os.Binder interface—providing the client access to the AIDL methods).
When the client receives the IBinder in the onServiceConnected() callback, it must callYourServiceInterface.Stub.asInterface(service) to cast the returned parameter to YourServiceInterface type. For example:
发表评论
-
我今天打算推荐一下近期自己制作的一款app-吃惑
2016-07-13 17:12 492你是否有这样的习惯 ... -
android listview优化几种写法详细介绍
2015-02-18 14:58 769这篇文章只是总结下getView里面优化视图的几种写法,就像 ... -
利用convertView优化ListView性能
2015-02-18 14:26 711这里提到的ListView只是作为一个典型代表 其实在A ... -
Android之ListView原理学习与优化总结
2015-02-05 15:50 738在整理前几篇文章的时候有朋友提出写一下ListView的性 ... -
sleep()和wait()有什么区别
2015-02-04 09:38 797sleep就是正在执行的线程主动让出cpu,cp ... -
线程与进程的区别
2015-01-27 20:12 705线程是指进程内的一个执行单元,也是进程内的可调度实体.与进程 ... -
线程同步的几种方式(转)
2015-01-27 19:58 883进程中线程同步的四种常用方式: 1、 临界区(CCrit ... -
Eclipse提示No java virtual machine
2014-12-15 16:22 1074当你启动eclipse时出现... No java v ... -
解决客户端向服务器端传输中文乱码问题
2014-10-24 09:59 998客户端加码 Java code? ... -
重要通告
2012-02-05 11:36 920博客涉及到的所有源码,包括网站源码、Android源码等均在千 ... -
关于Android发送邮件
2011-09-11 08:40 3391Google 在发表 Android 手机平台时,强调的是超强 ... -
ImageButton点击背景切换事件
2011-08-23 14:30 2514问题:imagebutton初始显示图片1,当单击该image ... -
Android中ImageButton的运用详解
2011-08-23 14:13 2337ImageButton在Android的运用非常灵活,既可以在 ... -
Android拍照、录像、录音代码范例
2011-08-19 09:17 1303package com.cons.dcg.collect; i ... -
Android的Menu状态动态设置方法onPrepareOptionsMenu(Menu menu)
2011-08-12 11:49 2068覆盖onPrepareOptionsMenu(Menu men ... -
ArrayAdapter和BaseAdapter的区别是什么
2011-08-11 18:10 2169近期很多Android开发者来函表示对ArrayAdapt ... -
有关代码结构的优化若干
2011-08-11 18:08 1066避免建立对象 世界上没有免费的对象。虽然GC为每个线程都建立 ... -
ArrayAdapter和List的关系
2011-08-11 18:00 21771、使用ArrayAdapter(数组适配器)顾名思义,需要把 ... -
Manifest权限大全
2011-08-09 17:38 1089<uses-permission android:nam ... -
Android中创建自己的ContentProvider
2011-08-09 17:37 1390Android是如何实现应用程序之间数据共享的?我们以 ...
相关推荐
AIDL(Android Interface Definition Language)是Android提供的一种用于实现进程间通信的工具,它允许开发者定义接口,使得服务能够被其他应用调用,即便这些应用运行在不同的进程中。** ### AIDL简介 AIDL是一种...
**AIDL(Android Interface ...总结,AIDL是Android中实现进程间通信的重要工具,它简化了跨进程服务调用的复杂性,提高了应用的交互能力。通过学习和掌握AIDL,开发者可以构建更健壮、功能更丰富的Android应用程序。
本示例"AIDL进程间通信DEMO"将深入讲解如何使用AIDL来建立两个应用程序组件之间的桥梁。 首先,我们需要了解AIDL的基本概念。AIDL允许开发者定义一个接口,这个接口将在两个进程间被实现和使用。通过AIDL定义的接口...
aidl跨进程通信的简单例子,有客户端和服务端。客户端绑定服务,即可发送内容到服务端。如果绑定服务失败,请添加代码:intent.setPackage("com.example.alidservice");即可
AIDL(Android Interface Definition Language)是Android提供的一种工具,用于方便开发者实现进程间通信。这篇博客“使用AIDL实现进程间通信”将深入探讨如何利用AIDL进行跨进程的交互。 首先,我们要理解AIDL的...
使用AIDL实现进程间通信 两个工程即两个APP,实现数据共享 APP1中有个service 不停的对某一个数进行++操作, APP2通过AIDL 获取APP1的Service中的这个值(通过回调) 当然要使用AIDLAPP1中也要做相应处理
需要注意的是,由于进程间通信涉及到数据的序列化和反序列化,因此AIDL支持的基本数据类型有限,如int、String等。对于复杂对象的传递,需要自定义Parcelable或Serializable接口的实现。 总结来说,AIDL在Android中...
综上所述,AIDL是Android平台中实现进程间通信的重要手段,通过合理的使用,可以构建出高效、稳定、可扩展的应用程序。通过阅读和理解给定的`MyTestAIDL`代码资源,开发者可以更好地掌握AIDL的工作方式,为今后的...
**Android进程间通信(IPC):深入理解AIDL** 在Android系统中,应用程序通常运行在各自的进程中,为了实现不同应用程序间的交互,Android提供了多种进程间通信(IPC, Inter-Process Communication)方式,其中之一...
在Android系统中,AIDL(Android Interface Definition Language)是一种用于实现进程间通信(IPC, Inter-Process Communication)的机制。AIDL允许一个应用服务在不同的进程中运行,使得其他应用能够与之交互,共享...
高仿360手机卫士,金山手机卫士等手机安全维护软件的大部分功能,已实现来电-短信拦截、手机应用、进程管理、缓存清理等功能,其中使用AIDL进程间通信技术,调用系.zip
总结来说,AIDL是Android系统中用于进程间通信的重要工具,通过它我们可以定义接口并在不同的进程中调用。服务端通过实现AIDL接口并返回`Binder`实例,客户端则通过绑定服务来获取接口并调用方法。理解并熟练掌握...
本教程将深入探讨如何使用AIDL和Binder连接池在两个Android应用之间实现进程间通信。 **AIDL基础** AIDL是一种声明式的语言,用于定义服务接口,使得客户端和服务器端可以在不同的进程中调用对方的方法。在Android...
Android进程间通信 AIDL Service 一、服务端结构 服务端需要处理的有: 1.处理对象,对象内方法,注意:AIDL 只能对函数起作用; 2.处理服务; 3.配置文件; 二、客户端 配置 1.对象,切记,与服务端的对象完全一致...
文件包含两个工程,Client和Server,通过aidl实现客户端和服务端之间的通信。 服务端和客户端都创建一个aidl文件,定义接口。 服务端通过service将接口暴露给客户端,客户端绑定服务。 解压即可运行。
在Android系统中,进程间通信(IPC,Inter-Process Communication)是实现不同应用程序之间数据交换的关键技术。AIDL(Android Interface Definition Language)是Android提供的一个工具,用于在不同进程间定义和...
下面将详细介绍Aidl在不同进程间通信中的应用及其工作原理。 **1. Android进程通信的重要性** Android系统设计时,每个应用运行在自己的进程中,为了保护应用间的隔离性和安全性。但有时我们需要让一个应用调用另一...