On Sat, Apr 30, 2011 at 4:05 PM, MarcoAndroid <[email protected]> wrote:

> 1) Does that mean that for all calls of the client to the service's
> methods you need to try/catch the DeadObjectException? Even
> getService() in onServiceConnected() can throw it?
>

You need to catch them wherever they can be thrown.  You actually don't need
to worry about this, because this is a checked exception so if you forget to
check it somewhere you will get a compile time error.


> 2) If my service only uses a local binder (LocalBinder in the example
> from the above link), so it is private to my own application and runs
> in the same process as the client, can I then still get
> DeadObjectException? I wonder because I see with this type of binding
> that the service does *not* appear in the services overview of a
> device or emulator, which makes sense to me because it is "tightly"
> connected to the activity that bound to it. That to me means you (nor
> the Android runtime) can end the service on its own, so never a chance
> on DeadObjectException... True?
>

No you can't get it, because it is in the same process, so if the service's
process goes away then your client code's process has gone away as well and
never could have gotten a result.

However because the interface generated by aidl can be used with a remote
object, at compile time there is no way to know whether or not this will be
the case, so the interface methods must declare they throw RemoteException
and you thus must handle if if calling those methods.

One way to get around this is when implementing those methods in the service
do not declare them as throwing RemoteException and on the client side cast
the interface to this implementation class.  Now the compiler knows that a
call to the method will never throw that exception.

Or just catch the exception and do nothing, or print a quick log, or
whatever.

-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to