Xamarin: A Tool to Develop Cross-Platform Mobile Apps

advertisement
Xamarin: A Tool to Develop Cross-Platform Mobile Apps
Xamarin announced Xamarin Studio, a tool that allows developers to build mobile applications using the C#
language. In addition, Xamarin announced its integration with Microsoft’s Visual Studio, allowing developers to
continue using their favorite development environment to build mobile apps.
The Platform War Goes On
Two platforms stand shoulder to shoulder: Apple's iOS and Google's Android.
Why Xamarin?
There are three types of mobile apps that developers can write: native, Web apps, and a combination.
Native apps run directly on the mobile device. They make use of the hardware features available on the
device, such as a camera and sensors such as an accelerometer, a compass, etc. Native apps are feature-rich
and interactive, with full access to the hardware. This approach, although good, requires developers to learn a
specific language for each platform: Objective-C for iOS and Java for Android. For companies that require apps
to run on multiple platforms, it’s expensive to maintain different code bases for multiple platforms, which are
usually not easily ported to the other platforms.
The second types of apps, Web-apps, are applications that run off the Web browser. To use them, users have
to launch the Web browser on the device and navigate to the correct URL. Web apps run within the confines of
the Web browser, which restricts them from accessing most parts of the hardware. Web apps tend to be less
interactive and are limited in scope and functionalities. Web apps, due to their ubiquitous access, have the
greatest benefits-the ability to "write once and run everywhere," to borrow the slogan from Sun Microsystems.
However, "write once, run everywhere" also means that the app will look the same everywhere. This limited the
usability of the apps, as their UI must be written to the lowest-common-denominator. But the upside of using
this approach is that Web apps are relatively easy (and less expensive) to build-developers simply need to
know HTML, JavaScript, and CSS.
A third approach to building apps is to take the best of both approaches and combine them: Use native code
for portions of the code that need to access specific hardware features of the device and use Web languages
(HTML, JavaScript, and CSS) for the rest. Although this approach sounds enticing, hybrid apps suffer from
performance issues, and are not easily scalable as the user base increases.
Xamarin's approach is to let developers create UIs that are unique to each platform, and then create
components that can be reused easily on another platform, using the C# programming language.
Xamarin takes the middle path; it respects the uniqueness of each platform and does not force developers to
create apps that look the same on all platforms. On the contrary, it encourages developers to take advantage
of the features that each platform offers.
Xamarin also recognizes that beyond the surface (user interface), apps have a lot of highly reusable
components that can be shared across platforms. For example, your code for accessing Web services can be
reused easily on the iOS and Android platforms.
Also, database code is also highly portable. Xamarin's approach is to let developers create UI that are unique to
each platform, and then create components that can be reused easily on another platform.
1
What about the language? Instead of using different languages for different platforms, a unifying language is
needed: C# was chosen because it’s easy to learn, and it’s the language of choice for many .NET developers.
Using C# allows Xamarin to reach out to millions of potential developers.
Integrated Development Environment (IDE): Xamarin Studio
The IDE plays a very important role. A good IDE enables acceleration of any development effort. Xamarin offers
the Xamarin Studio (in addition to Visual Studio support), which is a world-class IDE that makes developing,
debugging, testing, and packaging applications (and more) a walk in the park.
Platforms Supported by Xamarin
To write iOS apps, you need a Mac or a reasonable facsimile. Xamarin offers three broad choices:

Use Visual Studio on Windows. Using Visual Studio, you can develop iOS and Android apps natively on
your Windows computer. However, the caveat here is that in order to test iOS applications, you need to
have access to a networked Mac, which will provide the build and deployment services.

Use Xamarin Studio on Windows. Instead of Visual Studio, Xamarin provides its own IDE: Xamarin Studio.
Like Visual Studio, Xamarin Studio provides a world-class development environment to accelerate your
development effort. Like option 1, testing iOS applications requires access to a networked Mac.

Use Xamarin Studio on a Mac. This is the best option if you are developing applications for both iOS and
Android. Xamarin Studio's tight integration with Xcode makes designing and testing iOS applications easy.
How Xamarin Works
In a nutshell, Figure Below shows how Xamarin works.
You write your UI code for each specific platform-one for
Android and one for an iOS device. Then write business
logic that can be reused on both platforms.
Xamarin exposes all the APIs available in iOS and Android
to your application as regular C# class libraries. In
addition, your apps have access to a fully functional
implementation of the .NET runtime, which is bundled
with your app so that your code executes with all the
power of C# and .NET, such as memory management, etc.
When you are ready to compile the application for each
platform, Xamarin produces an ARM binary for iOS and
takes advantage of just-in-time compilation for Android.
As Xamarin apps are compiled to native binary, they are
able to perform without any performance degradation that you might expect from cross-compiled apps.
Source: http://www.codemag.com/article/1401051
Shared by Sh. Anuj Dhangar, DIO Lahaul-Spiti
2
Download