Generic Binder object from external jar

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Generic Binder object from external jar

Christian

Hello,

 

could someone please tell me how to solve the following issue, if that’s possible at all?

 

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

 

I embedded the JAR into a “Java Bindings Library” project and included this one into mine. I can obviously start the service and the onServiceConnected methods is called.

 

Kind regards

Christian

 


_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|

Re: Generic Binder object from external jar

venkatesh
Hi,

Please refer below link . it may be useful for your issue.

http://mono-for-android.1047100.n5.nabble.com/Bound-Services-td4872509.html

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Generic Binder object from external jar

Christian
Thank you for your answer. I'm afraid the issue described in the link you posted is of a different kind.


-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von venkatesh
Gesendet: Donnerstag, 12. September 2013 12:32
An: [hidden email]
Betreff: Re: [mono-android] Generic Binder object from external jar

Hi,

Please refer below link . it may be useful for your issue.

http://mono-for-android.1047100.n5.nabble.com/Bound-Services-td4872509.html
<http://mono-for-android.1047100.n5.nabble.com/Bound-Services-td4872509.html>  

Thanks



--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/Generic-Binder-object-from-external-jar-tp5713513p5713514.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|

Re: Generic Binder object from external jar

Jonathan Pryor-2
In reply to this post by Christian
On Sep 12, 2013, at 5:59 AM, "Breyer, Christian" <[hidden email]> 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
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid