July 1, 2015 // By Brent Edwards
This is the third part in a 5 part series. In the first part, we looked at creating a Xamarin.Forms app and why you would want to use MvvmCross with it. In the second part, we looked at adding MvvmCross to your Xamarin.Forms app. In this post, we will get the app running on the Android platform.
We’re going to dive right into the code, where we left off.
In the Android project
- Add a Helpers folder
- Add the Helpers/IMvxPageNavigationProvider interface
- Add the Helpers/IMvxPageNavigationHost interface
- Add the Helpers/MvxPagePresenter class
- Update Setup to override CreateViewPresenter method and return the newly created presenter
In the Portable or Shared project:
- Add the Helpers/IUiContext interface and the Helpers/UiContext class
In the Android project:
- Add the Helpers/MvxNavigationActivity class
- This is a good starting point: https://github.com/Cheesebaron/Xam.Forms.Mvx/blob/master/Movies/Movies.Android/MvxDroidAdaptation/MvxNavigationActivity.cs
- Change SplashScreen to override InitializationComplete and add:
Good news! You should now have your Android app up and running. I say should because there are a couple of gotchas you may have run into.
First, with the Shared project type, there may be some iOS code that doesn’t compile. It should be safe to comment that out for the moment. We’ll come back to it later.
Second, with the WinPhone project, there may be some compiler errors around string resources. This is likely due to the fact that we removed WinPhone from the namespace declaration. Make sure the using statements have the updated namespace.
In the next part, we’ll look at getting the app up and running for WinPhone.
You’ve just read part 3 of the “Comprehensive Guide to Creating a Xamarin.Forms App with MvvmCross” blog series. To read part 4, click here. If you’d like to contact Magenic, email us or call us at 877-277-1044.