Monday, September 07, 2009

Android: IPC using AIDL(Java)

http://developer.android.com/intl/zh-TW/guide/developing/tools/aidl.html
http://www.android1.net/Topic.aspx?BoardID=11&TopicID=391
http://owenhuangtw.pixnet.net/blog/post/23760257

As stated in doc from google, you need following steps:

Service: To implement an IPC service using AIDL
1. Create your .aidl file
2. Add the .aidl file to your makefile
3. Implement your interface methods
4. Expose your interface to clients

Client: Calling an IPC Method

1.Declare a variable of the interface type that your .aidl file defined.
2.Implement ServiceConnection.
3.Call Context.bindService(), passing in your ServiceConnection implementation.
4.In your implementation of ServiceConnection.onServiceConnected(), you will receive an IBinder instance (called service). Call YourInterfaceName.Stub.asInterface((IBinder)service) to cast the returned parameter to YourInterface type.
5.Call the methods that you defined on your interface. You should always trap DeadObjectException exceptions, which are thrown when the connection has broken; this will be the only exception thrown by remote methods.
6.To disconnect, call Context.unbindService() with the instance of your interface.



No comments:

Related Posts Plugin for WordPress, Blogger...