AIDL简述Word文档下载推荐.docx
《AIDL简述Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《AIDL简述Word文档下载推荐.docx(14页珍藏版)》请在冰豆网上搜索。
![AIDL简述Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2022-11/18/9da517c6-018f-46f4-9a33-ee5fc79993e8/9da517c6-018f-46f4-9a33-ee5fc79993e81.gif)
{
3.
String
greet(String
someone);
4.}
在Eclipse插件的帮助下,编译器会自动在gen目录中生成对应的IPerson.java文件,格式化后的代码如下:
2.
3.public
interface
extends
android.os.IInterface
4.
/**
Local-side
IPC
implementation
stub
class.
*/
5.
public
static
abstract
class
Stub
android.os.Binder
implements
com.scott.aidl.IPerson
6.
7.
private
final
java.lang.String
DESCRIPTOR
=
"
com.scott.aidl.IPerson"
;
8.
9.
Construct
the
at
attach
it
to
interface.
10.
Stub()
11.
this.attachInterface(this,
DESCRIPTOR);
12.
}
13.
14.
15.
*
Cast
an
IBinder
object
into
interface,
16.
generating
a
proxy
if
needed.
17.
18.
asInterface(android.os.IBinder
obj)
19.
((obj
==
null))
20.
return
null;
21.
22.
iin
(android.os.IInterface)
obj.queryLocalInterface(DESCRIPTOR);
23.
(((iin
!
null)
&
(iin
instanceof
com.scott.aidl.IPerson)))
24.
((com.scott.aidl.IPerson)
iin);
25.
26.
new
com.scott.aidl.IPerson.Stub.Proxy(obj);
27.
28.
29.
android.os.IBinder
asBinder()
30.
this;
31.
32.
33.
@Override
34.
boolean
onTransact(int
code,
android.os.Parcel
data,
reply,
int
flags)
35.
throws
android.os.RemoteException
36.
switch
(code)
37.
case
INTERFACE_TRANSACTION:
38.
reply.writeString(DESCRIPTOR);
39.
true;
40.
41.
TRANSACTION_greet:
42.
data.enforceInterface(DESCRIPTOR);
43.
_arg0;
44.
_arg0
data.readString();
45.
_result
this.greet(_arg0);
46.
reply.writeNoException();
47.
reply.writeString(_result);
48.
49.
50.
51.
super.onTransact(code,
flags);
52.
53.
54.
Proxy
55.
mRemote;
56.
57.
Proxy(android.os.IBinder
remote)
58.
mRemote
remote;
59.
60.
61.
62.
63.
64.
65.
getInterfaceDescriptor()
66.
DESCRIPTOR;
67.
68.
69.
greet(java.lang.String
someone)
70.
_data
android.os.Parcel.obtain();
71.
_reply
72.
_result;
73.
try
74.
_data.writeInterfaceToken(DESCRIPTOR);
75.
_data.writeString(someone);
76.
mRemote.transact(Stub.TRANSACTION_greet,
_data,
_reply,
0);
77.
_reply.readException();
78.
_reply.readString();
79.
finally
80.
_reply.recycle();
81.
_data.recycle();
82.
83.
84.
85.
86.
87.
TRANSACTION_greet
(android.os.IBinder.FIRST_CALL_TRANSACTION
+
88.
89.
90.
android.os.RemoteException;
91.}
该文件的大纲视图如下:
IPerson接口中的抽象内部类Stub继承android.os.Binder类并实现IPerson接口,比较重要的方法是asInterface(IBinder)方法,该方法会将IBinder类型的对象转换成IPerson类型,必要的时候生成一个代理对象返回结果。
接下来就是我们的Service了:
com.scott.server;
3.import
android.app.Service;
4.import