Xamarin: Simple Cross platform Alarm app
xamarin
Solution
I've been focusing on how to best share code between Android and iOS these past couple of weeks and here are my suggestions based on my experiences:
a) In general, you can share anything between platforms that is not platform specific.
I tend to use presenters or mediators that hold a reference to a view that is defined by an interface. For example, if I had a Login View, I would have my iOS UIViewController and my Android Activity both implement an ILoginView interface. This interface would have the following defined:
- Getters for Username and Password
- An event called LoginSubmitted
- Two methods ShowLoginFailed and GoNextScreen
The presenter/mediator would be responsible for listening to the login being submitted, get the username/password, and passing those things off to a service call or command. Whenever the mediator received the results of the command/service it would then be responsible for invoking either ShowLoginFailed or GoNextScreen.
I have also used interfaces for defining my SQLite Manager (https://github.com/praeclarum/sqlite-net/tree/master/src) , or a delegate that is responsible for making the actual web API service call. I've found I've had to do this because there is some platform specific compiling that needs to happen for the SQLite manager and RestSharp.
Long story short, interfaces are your friend especially when you couple them with some sort of Dependency Injection system.
b) If you are wanting your user to be prompted with an alarm when their device is in sleep mode or when they are in another app, I'd use AlarmManager for Android and LocalNotification for iOS.
c) You can kind of sort of use PCLs with Xamarin.Android and Xamarin.iOS. The problem is that PCLs are not 100% supported yet. However, there are some tweaks you can make to your dev environment that should hopefully get you where you want:
Switch to the Beta or Alpha channel in Xamarin Studio: "Xamarin Studio" -> "Check for Updates" -> Change the channel in the combo box in the upper left of the dialog box that pops up -> Select "Restart and Install Updates." This will let you have both Android and iOS projects be able to link to the same PCL in the same solution.
After updating XS, close XS and follow the instructions in this post to modify your Mono install so PCLs properly compile: MonoDevelop: is it possible to switch PCL's compiler?
To get code hinting to play nicer inside your PCL project, you'll need to grab the mscorlib.dll from your Mono install and place it in a DLLs folder in your project directory and add a reference to it in your PCL project. You can find the dll here: /Library/Frameworks/Mono.framework/Versions/3.0.10/lib/mono/4.0
Once you have done all of that, you should be in pretty good shape getting your PCL to work. I've found that this has been worth the extra work in that I can now create a Unit Test project in XS link it to the PCL and run tests from within the IDE. In addition, I can use libs like Moq to mock my views and do integration tests.
Xamarin is promising that full PCL support will be coming "soon" and we won't have to bother with these hacks.
Problem
Goal: Developing a cross platform mobile app using Xamarin studio that shows a message at certain date and time. Questions: a) What things will/can be shared between platforms if i want to develop such application. (A structural design With possible classes will be appreciated) b) Is it better to use a Timer or AlarmManager? c) What type of project should be created for the Shared Core Project (Portable Class Library/Platform Specific Library/Plain C# Project)? Thanks in Advance.