[mono-android] Binding services

Jonathan Pryor jpryor at novell.com
Tue Mar 22 21:22:58 EDT 2011


On Mar 22, 2011, at 8:15 PM, Brian Long wrote:
> Am I right in thinking that binding to a service is not on the table with MonoDroid?

Binding to a service and using AIDL are related but not identical.

You _can_ start a Service using Context.StartService()[0], bind to a service using Context.BindService()[1] , unbind using Context.UnbindService()[2], and use the service. We even have a sample [3, 4]. :-)

Where AIDL comes in is when you want to use Inter-Process Communication to a Service hosted in another process, as AIDL is used to describe the messages that can be sent to the Service. This is not currently "natively" supported by Mono for Android, but it should be possible to use Mono for Android's Java interop features [5, 6] to run the `aidl` program as a pre-build step to generate .java sources, then implement and include those .java sources into your build so that your app and other apps may use them.

 - Jon

[0] http://docs.mono-android.net/index.aspx?link=M%3aAndroid.Content.Context.StartService(Android.Content.Intent)

[1] http://docs.mono-android.net/index.aspx?link=M%3aAndroid.Content.Context.BindService(Android.Content.Intent%2cAndroid.Content.IServiceConnection%2cAndroid.Content.Bind)

[2] http://docs.mono-android.net/index.aspx?link=M%3aAndroid.Content.Context.UnbindService(Android.Content.IServiceConnection)

[3] https://github.com/mono/monodroid-samples/blob/master/ApiDemo/App/LocalService.cs

[4] https://github.com/mono/monodroid-samples/blob/master/ApiDemo/App/LocalServiceActivities.cs

[5] http://mono-android.net/Documentation/API_Design#Jave_Native_Interface_Support

[6] https://github.com/mono/monodroid-samples/tree/master/GoogleMaps



More information about the Monodroid mailing list