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
1 comment:
Got to look again at Services, but I think it will be very handy next time I have to code a Service.
I tried on ISecondary.aidl in the from ApiDemos, got broken though. Two pieces of advice:
$f =~ s/\/\*.*?\*\///sg; Add global marker to erase all comments
$m->{arglist} do not need to die if is not set, think of a method which have no arguments.
Post a Comment