Donal,

No, a service is a service, and a binder is a binder.

The binder you get in the callback is the binder returned by the service's onBind.

This example:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LocalService.html

has a binder implementation that returns a reference to its service, so you can do this

public void onServiceConnected(ComponentName className,
             IBinder binder) {

LocalService.LocalBinder binder = (LocalService.LocalBinder) binder;
*LocalService service = binder.getService();*
}

This example has one flaw: it leaks a service reference (since LocalBinder is a non-static inner class of LocalService). Using a static inner or a top-level class for LocalBinder, fixes that (AFAIK).

-- Kostya

13.09.2010 13:16, Donal Rafferty ?????:
09-13 10:06:53.566: ERROR/AndroidRuntime(18791): Uncaught handler: thread main exiting due to uncaught exception 09-13 10:06:53.676: ERROR/AndroidRuntime(18791): java.lang.ClassCastException: com.xxx.phone.MyService$1 09-13 10:06:53.676: ERROR/AndroidRuntime(18791): at com.xxx.phone.ui.MyActivity$2.onServiceConnected(MyActivity.java:515)

So it doesn't like the cast from binder to Service?

How can I fix that do you know? What am I missing from the example?


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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