On Sep 12, 2013, at 5:59 AM, "Breyer, Christian" <[email protected]> wrote:
> I’m including an external JAR that exports a Service and a generic Binder
> class called LocalBinder<T>. The sample code on how to work with the JAR
> looks like this:
>
> public void onServiceConnected(ComponentName className, IBinder
> service) {
> Log.d(LOG_TAG, "Service connected...");
> mService = ((LocalBinder<SygicService>) service).getService();
> // …
> }
>
> The IBinder reference is of a different type (Android.OS.Binder) than in this
> Java sample.
I don't understand what this means.
> The C# LocalBinder class is not a generic one and I have no idea how to get
> to the Service-Reference of the Binder since I cannot just cast it.
LocalBinder isn't generic because Java generics don't exist. Java uses type
erasure, and when using Java through JNI -- as is done in Xamarin.Android --
the generics have been "erased".
You should be able to cast the service value to the LocalBinder type by using
the JavaCast<T>() extension method:
http://androidapi.xamarin.com/?link=M%3aAndroid.Runtime.Extensions.JavaCast%3CTResult%3E
For example:
mService = service.JavaCast<LocalBinder>().Service;
- Jon
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid