Understanding Xamarin Android

Understanding Xamarin Android


Xamarin.Android is a part of Xamarin family to build a native Android app with C# and Xamarin. Xamarin.Android provides the same UI controls as you have in Android with Java. In this article you will learn about the Android architecture, Xamarin. Android architecture and tools to develop Xamarin.Android apps. Before going to start Xamarin.Android, let's understand Android architecture and development tools with Java.

Android Development

Android is an open source operating system based on Linux kernel. Android was originally developed by Android Inc. and subsequently purchased by Google. Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The native Android apps development can be done using Android Studio or Eclipse using Java as a programming language.

xam 1.png


Android Platform Architecture

Android operating system is a Linux-based stack of software components which can be divided mainly into five sections as shown below in the following diagram.

xam 9.png


Linux Kernel

The Linux kernel provides a multitasking execution environment which allows multiple processes to execute concurrently. The Android Runtime (ART) relies on the Linux kernel for underlying functionalities such as threading and low-level memory management etc.

Hardware Abstraction Layer (HAL)

The hardware abstraction layer (HAL) allows the Android application/framework to communicate with the hardware specific device drivers with the help of higher-level Java API. The Android HAL contains multiple library modules for a specific type of hardware components, such as the camera or bluetooth module. So, when you make a call to access device hardware using Java API, the Android system loads the library module for that hardware component.

Android Runtime

Each android app based on Android version 5.0 (API level 21) or higher, runs in its own process and with its own instance of the Android Runtime (ART). ART has been written to run multiple vms (virtual machines) on low-memory devices. In order to execute app within an ART, the app code must be transformed from standard Java class files to the Dalvik executable (.dex) format, that's optimized for minimal memory (Consume 50% less memory) footprint than standard Java bytecode. Build toolchains, such as Jack, compile Java sources into DEX bytecode, which can run on the Android platform.

ART has two main features compared to Dalvik:

  • Ahead-of-Time (AOT) compilation, which improves speed and reduces memory footprint
  • Optimized garbage collection (GC)

Native C/C++ Libraries

C/C++ libraries provdes a wider range of functions including 2D and 3D graphics drawing, Secure Sockets Layer (SSL) communication, SQLite database management, media management like audio and video playback, display subsystem and graphic layer management and an implementation of the standard C system library (libc). The Android app can access these libraries through the Java-based Android core library APIs. Also, you can access these native C/C++ libraries using the Android Native Development Kit (NDK) within Java code using the Java Native Interface (JNI).

Java API Framework

The Java API Framework is a set of rich and extensible APIs to access entire feature-set of the Android OS using Java language. These APIs are helpful to interact Native C/C++ libraries, build rich UI and for various task management like Activity management, notification management, resource management etc.

System Apps and Third Party Apps

Android OS comes with a set of system apps for emails, phone calls, messages, calendars, internet browsing, contacts, and much more. Apart from system apps, you can also install third-party for emails, chats, messages like outlook, facebook, twitter etc.

Xamarin.Android Architecture

Xamarin.Android apps run within the Mono execution environment. The Mono runtime is written in the C language and runs side-by-side with the Android Runtime (ART) virtual machine. Both runtime environments run on top of the Linux kernel and expose various APIs to access the underlying android system.

In Xamarin.Android apps you can access the various low-level features of the Android operating system either by calling .NET APIs or using the classes exposed in the Android namespaces which provide a bridge to the Java APIs that are exposed by the Android Runtime.

Managed Callable Wrappers (MCW)

The Android OS facilities like Audio, Graphics, OpenGL, and Telephony are not available directly to native apps. They are only exposed through the Android Runtime Java APIs residing in one of the Java.* namespaces or the Android.* namespaces. So, to access these APIs in Xamarin. Android, a managed callable wrapper is required which acts as a JNI (Java Native Interface) bridge to invoke Android code and provide support for overriding virtual methods and implementing Java interfaces.

Android Callable Wrappers (ACW)

Android callable wrappers are a JNI bridge which is used to invoke managed code when the Android runtime needs. When an Android Callable Wrapper (ACW) is created from Java, the ACW constructor will cause the corresponding C# constructor to be invoked.

Xamarin.Android Development

Xamarin.Android allows you to build a native Android app using C#. A Xamarin Android project is based on the standard Android project structure as you create with Android Studio or eclipse. Xamarin.Android development you can do using IDEs - Xamarin Studio or Visual Studio for Mac and Visual Studio for Windows.

xam 1.png


What do you think?

I hope, now you have an understanding about Xamarin. Android to build native Android mobile apps. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Keyword

xamarin android, xamarin android tutorial, xamarin android deployment, xamarin android development, xamarin android designer,

Drop us a Query

About the author

Bhaskar

Bhaskar

The author has a keen interest in exploring the latest technologies such as AI, ML, Data Science, Cyber Security, Guidewire, Anaplan, Java, Python, Web Designing tools, Web Development Technologies, Mobile Apps, and whatnot. He bags over a decade of experience in writing technical content.

Corporate
whatsapp arrow
Loading...
// load third party scripts onload