I’m currently working on an XMPP app’ on Android and I’m pondering about the best way to throw a different type of Exception than a RemoteException to my activity from my service.
As it seems impossible to throw another thing than a RemoteException using IPC (you can’t declare to throw anything in your .aidl), I just see two solutions:
-
Create a listener for my activity to listen on my custom XMPP exception, which in fact will not be thrown but just sent as a usual object implementing the Parcelable protocol.
-
Catch my XMPPException and throw a RemoteException (with a content updated with my XMPPException) – But in that case, how could I know on my activity if it’s an XMPP or a real RemoteException ? By tagging the name of the exception and parsing it on my activity ? It would be really gore.
Do you have any idea ? Did I miss something from the SDK documentation ?
Thanks.
If #1 means what I think it does, I’d use that — have the service catch the exception and call a method on an AIDL-defined callback object created and supplied by the activity.
You can see an example of that technique in this client and service project, from one of my books.