int N = mCallbacks.beginBroadcast();
for (int i = 0; i < N; i++) {
try {
mCallbacks.getBroadcastItem(i).onSomeEvent();
} catch (RemoteException e) {}
}
mCallbacks.finishBroadcast();
This can quickly pollute the service implementation, and even if you factor these calls out to a separate class it can be a pain to create and maintain them. So, I came up with a solution in the form of a Perl script which takes as input an AIDL file defining the callback interface and outputs a class implementing the extended RemoteCallbackList. To use, simply type:
$ ./aidl-cbliststub.pl < IFooListener.aidl > IFooListenerCallbackList.java
Download: aidl-cblistsub.pl