Wow – Microsoft made a pretty big announcement today at Build 2016, no? Xamarin will now be included in all versions of Visual Studio … for FREE! This removes a pretty sizable barrier for people and companies from trying Xamarin and all of the cross platform development goodness it delivers … cost. So with the influx of developers coming to the Xamarin platform, I wanted to put together a post of concepts I think are important to know as a mobile developer. This isn’t a top 10 skills list, or “you must know everything here or you will fail” – but rather ideas I’ve found useful over the years as I’ve learned (and still am learning) cross platform mobile development using Xamarin.

But first … Congratulations!!

Before we get into it, I want to congratulate everybody at Xamarin. Everybody that I’ve had an encounter with at that company has been an utmost professional … knowledgable, personable, and a downright pleasure to work with. My user group had James Montemagno come to Madison to do a Dev Days, and the feedback I received afterwards was nothing but terrific. Jayme Singleton heads up the Community Outreach and is able to get us whatever support we need for user group meetings, conference talks, anything. I’ve reached out to Rob Gibbens on the Xamarin University team regarding running a user group (a topic not related to the coursework at all) and we swapped ideas back and forth. People on the various development teams are responsive and active in the forums and on Twitter. I’ve met a couple of “Xamarins” via this blog … all in all I’ve had nothing but great interactions with the company – and I wanted to give everybody there a big congratulations!

So … now what does a new .NET developer need to be thinking about before they jump into mobile?

Mobile Development Is Difficult

I could have easily had said that software development is difficult, but all too often I find that developers getting into mobile for the first time underestimate the complexity involved. iOS and Android are full blown OS’s – not pared down shells of something else. Just because the app runs on a small device does not mean it is small in complexity. And this goes double when you’re trying to write a codebase that will be shared across multiple platforms … in other words, shared across completely different operating systems.

With that said – having a solid grasp on C# fundamentals and some its more advanced topics are essential. Some that come to mind immediately:

  • Delegates and Lambdas
  • LINQ
  • XAML (yes, XAML – you’ll begin to really dig it with Xamarin.Forms)
  • Passing around Func’s and Action’s

I know you’re probably saying to yourself … those concepts aren’t new – nor are they very difficult. That’s kind of the point, Xamarin lets you use .NET and all the familiarness of the framework… be prepared to exploit it.

There’s one more concept that you should be familiar with as well …

ASYNCHRONOUS!

I always say that first rule of mobile development is “Don’t Block The UI Thread” … and the only way you can accomplish that is through asynchronous programming. Asynchronous is much more than just async, await and Task<T>. You’ll have to account for cancellations, exceptions, handling multiple threads and then sync’ing multiple threads back together. It can become messy quickly … brush up on it.

Platforms – iOS and Android Are Different!

The great thing about Xamarin is that it allows you to share code between the platforms. The bad thing about it is that it’s not apparent from the get-go that there still is a ton of platform-specific code that needs to be written. Android and iOS are different operating systems. The navigation metaphors are different, the way they handle accessing system resources are different, and I could go on … but the point is you’re going to need to be prepared to handle these differences somehow. It could be as simple as using dependency injection to inject the platform specific piece into the shared code layer … or you may have to get your hands dirty within the platform-specific projects themselves. In fact, I know you will (even if you’re writing a Xamarin.Forms app). So be prepared to dig through Apple’s or Google’s documentation and be prepared to implement the same thing completely differently on each platform. It seems obvious when you think about it … but the whole “shared code” thing can trip you up.

Also be aware of the limitations of the device and what could possibly go wrong. Are you expecting your app to have an internet connection to transmit data? What if the user goes offline? What’s the best way to store certain types of data? What happens if a phone call interrupts your app? If you’re downloading something – can it stop when the user closes the app? There are always answers to these questions … but be aware of them.

Design Patterns

There are several design patterns that will make your life a whole lot easier when doing mobile development. MVVM or Model-View-ViewModel is one. Essentially this pattern allows your entity, or data class to be presented in the view via the viewmodel (with the viewmodel abstracting the 2 from each other). MVVM frameworks such as the one bundled in Xamarin.Forms, MVVMCross, and RxUI provide other useful feature such as data binding, dependency injection, navigation, and a host of others.

You’ll want to become familiar with dependency injection – not just because it makes your code a whole lot more unit testable and resilient, but also because it’s a decent way to inject platform specific classes the shared layer of code.

Along with that – you’re going to want to know the pros and cons of Shared Projects vs PCLs. The way you structure your project could have major ramifications down the road.

3rd Party Frameworks

Don’t reinvent the wheel! There are tons, and I mean tons of libraries out there that are already cross platform (and thanks to some NuGet bait-n-switch trickery) can do platform specific things within shared code. So always be NuGet’ing!

Just a few that I’ve found useful:

In Summary…

All in all, creating mobile apps with Xamarin is a blast. There’s nothing like the feeling you get when seeing something work the same on both iOS and Android with the vast majority of the code shared between the two. But be aware that it does take some work to become proficient in the platform, but don’t get discouraged … mobile development is a ton of fun … and combine it with C#, it’ll be hard to do anything else! So welcome on board everybody – it’s going to be a fun ride!