Aidl learning

Aidl learning
How is data passed across processes
The two processes cannot directly mmunicate indirectly v> code>,> underlying layer of Android system
AIDL:android interface definition language
Android interface definition language
MOOC video learning address
Data types are supported by default
Basic data types String, CharSequencelist, MAppArcelable
steps
To create a binding service using AIDL, perform the following steps:
Create.aidl file
This file defines the programming interface with method signatures.

package com.example.android;
interface IRemoteService {

int getPid();

void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
        double aDouble, String aString);
}

The Android SDK tool generates an interface using the Java programming language based on your.aidl file. This interface has an internal abstract class called Stub that extends the Binder class and implements methods in the AIDL interface. You must extend the Stub class and implement the method.

private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
public int getPid(){
    return Process.myPid();
}
public void basicTypes(int anInt, long aLong, boolean aBoolean,
    float aFloat, double aDouble, String aString) {
    // Does nothing
}
};

Expose the interface
implementation Service to the client and override onBind() to return an implementation of the Stub class.

    public class RemoteService extends Service {
@Override
public void onCreate() {
    super.onCreate();
}

@Override
public IBinder onBind(Intent intent) {
    // Return the interface
    return mBinder;
}

private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
    public int getPid(){
        return Process.myPid();
    }
    public void basicTypes(int anInt, long aLong, boolean aBoolean,
        float aFloat, double aDouble, String aString) {
        // Does nothing
    }
};
}

Call the steps
To invoke the remote interface defined using AIDL, the calling class must perform the following steps:
Add the.aidl file to the project SRC/directory. Declares an instance of the IBinder interface (generated based on AIDL). Realize the ServiceConnection. Call Context.bindService() to pass in your implementation of ServiceConnection. In your onServiceConnected() implementation, you will receive an IBinder instance (named Service). Call YourInterfaceName. Stub. AsInterface ((IBinder) service), to the types of parameters can be converted into YourInterface will return. Invoke the method you defined on the interface. You should always catch DeadObjectExceptions, which are thrown when a connection is broken; This will be the only exception thrown by the remote method. To disconnect, call Context.unbindService() using your instance of the interface.

Steps are not introduced on the official website steps specific jump to the official website

Read More: