Skip to content Skip to sidebar Skip to footer

Android Asynchronous Aidl

I have a main app and a remote service app that connects each other using AIDL. I'm doing synchronous process successfully in remote service, but how can I do an asynchronous proc

Solution 1:

You can implement AIDL asynchronously, by creating a new AIDL (for callbacks) as :

import pack.addonlibrary.Action;

oneway interfaceIAddOnCallback {

    voidhandleOnClicked(List<Action> actionList);
}

And by changing onClicked method of IAddon aidl class from:

List<Action> onClicked(String url);

to:

voidonClicked(IAddOnCallback callback, String url);

After connecting to service and while calling onClicked method you can implement the callback object and can send that object to connecting service. Callback Stub (client) can be implemented as :

 IAddOnCallback.Stubcallback=newIAddOnCallback.Stub() {

    @OverridepublicvoidhandleOnClicked(List<Action> actionList)throws RemoteException {
        // here you can perform actions//shows toasts in main app
    }
};

This is how you can do tasks asynchronously. Hope it helps.

Post a Comment for "Android Asynchronous Aidl"