• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
AIDL  - Android Interface Definition Language
 

AIDL - Android Interface Definition Language

on

  • 1,839 views

Modified example from Marakana. Using AIDL Service to authenticate username and password

Modified example from Marakana. Using AIDL Service to authenticate username and password

Statistics

Views

Total Views
1,839
Views on SlideShare
1,838
Embed Views
1

Actions

Likes
2
Downloads
0
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    AIDL  - Android Interface Definition Language AIDL - Android Interface Definition Language Presentation Transcript

    • AIDL - Services and IPC
    • Inter Process Communication
    • The caller invokes Proxy. Proxy inturn binds the current activity to the remote service This is the Remote method. It is exposed as a Bound Service
    • droid Services - Basics ervice is an application component that can perform long­running operations in th kground and does not provide a user interface. ervice can essentially take two forms: rted : A service is "started" when a component (such as an activity) starts it by ing startService(). For example, it might download or upload a file over the networ und : A service is "bound" when an application component binds to it by calling dService(). A bound service offers a client­server interface that allows components nteract with the service, send requests, get results, and even do so across cesses with interprocess communication (IPC).
    • droid Services – Basics reate a service, you must create a subclass of Service . back methods you should override are: nd() : The system calls this method when another component wants to bind with t ice (such as to perform RPC), by calling bindService(). you must provide an interface that clients use to communicate with the service eturning an IBinder. reate() : The system calls this method when the service is first created, to perform ­time setup procedures (before it calls either onStartCommand() or onBind()). estroy() : The system calls this method when the service is no longer used and is g destroyed.
    • IDL – Android Interface Definition Language DL (Android Interface Definition Language) allows you to define the ogramming interface that both the client and service use to communicate using Android, one process cannot normally access the memory of another process. to talk, they need to decompose their objects into primitives that the erating system can understand, and marshall the objects across that boundary you.
    • vice Life Cycle
    • ypical Use Case
    • xample ACTIVITY Username, password Activity User details Activity Activity Remote Service
    • teps Create the .aidl file : This file defines the interface with method signatures. Implement the interface : The Android SDK tools generate an interface 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 mus extend the Stub class and implement the methods. Expose the interface to clients : Implement a Service and override onBind() to return your implementation of the Stub class.
    • Creating a .aidl file // Declare the interface. – IUserInfoService.aidl interface IUserInfoService { String getInfo(in String user, in String pass); } hen you build your application, the SDK tools generate a .java interface file named after your .aidl e. he generated interface IUserInfoService contains inner class Stub ­ IUserInfoService.Stub
    • . Implementing the interface eed to extend this class IUserInfoService.Stub by providing additional methods  return new IUserInfoService.Stub() { @Override public String getInfo(String user, String pass) throws RemoteException { // TODO Auto­generated method stub if (user.equals("arvind")) return "Welcome Arvind! You have 15 unread messages"; return user+pass; }
    • Exposing your interface in Service class e you've implemented the interface for your service,  need to expose it to clients so they can bind to it.  // UserInfoService public IBinder onBind(Intent intent) { return new IUserInfoService.Stub() { @Override public String getInfo(String user, String pass) throws RemoteException { // TODO Auto­generated method stub if (user.equals("arvind")) return "Welcome Arvind! You have 15 unread messages"; return user+pass; } };
    • ccessing Service in Activity Use ServiceConnection class � onServiceConnected gives reference to service interface service = IUserInfoService.Stub.asInterface((IBinder) boundService Access the methods of service service.getUserInfo(“….”,”….”);
    • dditional Info The bindService() method returns immediately without a value, but when the Android system creates the connection between the client and service, it calls onServiceConnected( on the ServiceConnection, to deliver the IBinder that the clie can use to communicate with the service.
    • ��������������������������������������������������������������������������� ��������������������������������������������������������������������������������� �����������������������������������������������������