What are the advantages of using AIDL
while we can use java interfaces to help client applications call the bound service?
For example, For ITestService
we should create an AIDL
as follows:
// ITestService.aidl
package com.varanegar.vaslibrary.service;
// Declare any non-default types here with import statements
interface ITestService {
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
int test();
}
Then we should implement the generated Stub
class:
public class TestService extends Service {
public class TestImpl extends ITestService.Stub{
@Override
public void basicTypes(int anInt, long aLong, boolean aBoolean,
float aFloat, double aDouble, String aString) throws RemoteException {
}
@Override
public int test() throws RemoteException {
return 0;
}
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return new TestImpl();
}
}
Though, I belive We can easily create a java Interface like this:
interface ITestService {
int test();
}
and then create our service that implements that interface:
public class TestService extends Service implements ITestService {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int test() {
return 0;
}
}
According to Wikipedia:
AIDL: Java-based, for Android; supports local and remote procedure calls, can be accessed from native applications by calling through Java Native Interface (JNI)
Is there any other compelling reason to use AIDL
instead of normal java services?
It seems to me that I can use bound and started services without any AIDL
. Because this is possible to write java interfaces in an android library as a contract between the server and all client applications.
I do not intend to create a native application. So if AIDL
is used to expose Java services to a native application, is it right to use that in my case? Am I right? Please correct me if I misunderestood AIDL
.
Thanks in advance
Service
object in your scenario. "According to Wikipedia" -- Wikipedia is incorrect, insofar as AIDL has little to do with JNI. "instead of normal java services?" -- what is a "normal java service"? "It seems to me that I can use bound and started services without any AIDL." -- within one process, yes, but not across processes. – Taynatayra