20171118_Building-Cross-Platform-app

Building Cross-Platform Apps with Xamarin

Building Cross-Platform Apps with Xamarin

When you hear about Xamarin then the first thing that comes to your mind is “Cross-platform”. But what is actually cross-platform and what does it mean? Before we move on to discussing app development with Xamarin we need to understand the meaning of cross-platform and how it is faring in the market.

What is Cross-platform?

Cross-platform applications or software are designed to run on multiple platforms. They can broadly be divided into two types:

1) The first one will need different compilation for each platform.

2) The second type will run on any platform without making any changes.

Cross-platform is important today because the conventional methods of developing an app are quite cumbersome. The developers had to go into a lot of complexities to build a mobile application that can run on multiple platforms. These applications are expensive to develop and also time-consuming. These processes have been simplified with the introduction of Xamarin.

What is Xamarin?

It is a development platform that allows you to build mobile applications using C#. It has also introduced its integration with Microsoft visual studio that can allow the developers to use their favorite platform for development. The two major platforms that are in great demand are Apple iOS and Google’s Android.

Why is it a good idea to switch to Xamarin?

Before we dive into the metrics of Xamarin and why it has suddenly become so popular among the mobile app developers let us understand the basics of mobile development. Mobile apps are certainly of three type Native, web apps, and cross-platform. Xamarin allows the developers to develop and write code for iOS, Windows, and Android. With Xamarin you get C# bindings to native Android and iOS API’s. This gives you an advantage of bringing in use all the features of iOS and Android that involves graphics, user interface, animation, notification, and others. In short, we can say that the application is cross-platform but is still native. Xamarin allows the user to develop code that is just not easy to write but also saves a lot of time and money.

Each time whenever a new development is reported in Android or iOS subsequently they are made available in Xamarin also and you get the matching API’s. Xamarin has several features such as garbage collection, LINQ(language integrated query), asynchronous programming features, delegates and a branching of WCF(windows communication foundation). Xamarin .Forms is a layer that exists over all the other UI bindings i.e Xamarin.iOS, Xamarin. Android and Windows phone API. It helps to enable the cross-platform user interface library.Let us now talk about how to write cross-platform applications with Xamarin.

When a developer starts working with Xamarin he has to choose between the two available project types:

>> Shared Project

>> Portable class library(PCL)

1) Shared Project:

A shared project allows the developer to write codes that are specific to a particular platform. The code that you write will contain the compiler directive that will be responsible for enabling or disabling those parts of the code that is specific to the application project that is using the code.

2) Portable class library (PCL) :

When working with PCL then the developer will be able to write code that can be run on multiple platforms but with a certain restriction. As it is known that not all .net API’s will be available on all platforms you will be able to run the code only on the targeted platform. During the building process, the PCL will be compiled into separate DLL’s and will be loaded only during the runtime. When working on a shared project no separate dll is created rather the final projects is inclusive of the code.

Why is it a good idea to switch to Xamarin?

Visual Studio on Windows:

If you want to develop an iOS application or an Android application you can work it out on a Windows computer itself. The only catch here is that in case of iOS applications you will need to have a networked Mac which will be providing build and deployment platform.

Xamarin studio:

Xamarin also offers its own IDE which accelerates the building and developing process with the help of a world-class development environment. Here again, in case of iOS application, you will need to have a networked Mac.

Xamarin studio on Mac:

This is the best one to work through in case you are working towards creating an Android as well as iOS application. This eliminates the need for a networked Mac for testing the iOS applications. The tight integration of Xamarin studio with Xcode make the testing and building much easier.

Cross-platform code and defining its structure:

The common approach of Xamarin is to allow developers to write and create UI’s that is specific to each platform, followed by creating components in C# programming language that can be easily used on another platform.

The one thing that is very important especially for the developers is well structured and bug-free code. Developers have to write the same code logic twice or thrice according to the platform they are working on. Xamarin has a mechanism that allows the writing of reusable code much easier. You can write the code once and reuse it for other platforms as well without much hassle.

MVVM (Model – view - ViewModel) cross architecture :

MVVM cross is the architecture on which Xamarin works. MVVM cross entirely depends on the MVVM architectural pattern. It comes with a bunch of libraries, API’s and other utilities that make the cross-platform development much easy. It allows leveraging the MVVM features to the maximum by reducing the boilerplate code and increasing the code reusability.

Summary:

We have seen various aspects of Xamarin and how it works. But few things should be kept in mind about Xamarin that it is not a “write once and run anywhere” tool. It rather focuses on the fact that all platforms have their own uniqueness and all applications behave differently on different platforms. Xamarin preserves the uniqueness quotient of all platforms and makes the developers understand it too. The business logic is highly reusable and that is where Xamarin is the winner.

Related Posts