bmgsmith
bmgsmith

Reputation: 58

Is Xamarin the right choice for Android and IOS long running service

My specific task requires that I write a long running service for Android. The service should be running all the time unless the user specifically shuts it down. This I can do. However, one of my managers suggested I look into using Xamarin so we could also run this on Windows 10 and iOS. I have no experience with Xamarin or iOS so I am struggling to find any advantage to using Xamarin for this specific task, other than perhaps the code base is all in C#.

1) Does anyone have any experience with writing this type of service in Xamarin for multiple OS and if so can you offer any insight?

2) Will I have to write separate c# code for the Android, iOS and Windows implementations of the service?

3) If anyone has any compelling reasons to champion Xamarin for this task please let me know your thoughts.

Thanks

Upvotes: 1

Views: 135

Answers (1)

Arpit Ratan
Arpit Ratan

Reputation: 3026

Xamarin has ported all the Android / iOS libraries to C#. Hence you can write the code in C# language but the Android Service still works in the same way.

What you will essentially do is create a PCL code (shared library) which can be used across the platforms like iOS / Android. All you business logic goes here in this library. Make sure any platform specific code is not here.

Now you will create separate projects for Android and iOS which will use the above mentioned PCL library. This is platform specific non PCL code.

For example : In Android Project, you will still use StartService(intent) to start the service but say onHandleIntent(), you will call the PCL(shared library) code. I would recommend to inject the dependency on PCL code as and when required.

Please Note : If the lines of code in the shared library is considerably very less as compared to platform specific code then it makes no sense to choose Xamarin over native.

Upvotes: 1

Related Questions