Xamarin is a free and open-source platform for building cross-platform mobile applications using C# and the .NET framework. It allows developers to use a single codebase to develop complex yet high-performance mobile applications for iOS, Android, and Windows quickly and at a reduced cost. Our experts and seasoned interviewers have compiled top Xamarin interview questions and answers that will help you crack your next Xamarin job interview for beginner, intermediate and expert roles. Check out how to frame answers for questions from topics like code sharing, dependency services, custom renderers, Effects, flavors, MVVM, XAML, Trigger, databases, forms and more. If you are planning to make a career as a Xamarin App Developer but are confused about what to do to answer those tricky interview questions in your Xamarin job interviews, this list of interview questions with detailed answers will be the perfect guide for you. Attempt all questions with confidence and self-assurance.
Xamarin.Android applications depend on Microsoft's Mono Virtual Machine. Mono is Microsoft's open-source implementation of the .Net Framework based on open standards for C# and CLR. Launched in the year 2001, it was mainly created to allow .Net applications to work on Linux platform, but was later modified to support development on various devices including embedded systems.
In Xamarin, Mono works in parallel with Android's ART. On Android, most of the system facilities like Audio, Graphics, OpenGL, and Telephony are not available directly to native applications, they are only exposed through the Android Runtime Java APIs residing in one of the Java.* namespaces or the Android.* namespaces. The native applications interact with the exposed .NET APIs. These APIs then, through Android Binding call the underlying Android Runtime Java APIs. The architecture is roughly like this.
While writing Xamarin Cross-Platform Applications, one might encounter a lot of instances where similar functionality needs to be implemented across various platforms, which is generic. To facilitate this and allow code reuse, it makes utmost sense to share some common piece of code between these platforms as it saves time, reduces error scope and is easy for maintenance.
Xamarin provides three common approaches to share code between Cross-Platform Applications:-
1. .NET Standard Libraries
.NET Standard Libraries is a way to share common code over multiple runtimes. .NET Standard is a set of specifications which various .NET runtimes adhere to and hence code written for one version of .NET Standard works on multiple versions of .NET runtimes like .NET Core, Mono, etc. You can write your code and compile it into .NET Class Library and share it with others.
The primary benefits of using this approach are:
2. Using Shared Projects
Shared Projects are the usual .NET application projects that contain code files and assets. Shared Projects are meant to be included in other projects and help in code reuse. It is a code level sharing technique.
A cross-platform application that supports iOS, Android, and Windows would require an application project for each platform and a separate Shared Project for the code common to all.
So, if you are creating a cross-platform app for Android, iOS, and Windows, you will usually have the following projects
A Shared Project is not directly compiled. In other words, no DLL file is produced in the compilation process. Instead, the files are compiled into the same DLL as the project that references it. This way, it is possible to write blocks of platform-specific code in the Shared Project that will only be compiled by the specific platform.
The advantages of using this technique are:-
They do not produce any output assembly of their own. Hence, not used for sharing and distributing to other developers
3. Portable Class Libraries (Deprecated)
When you create an Application Project or a Library Projection compiles into a DLL, it is restricted to work only on a specific platform, i.e. the one it is created for. This is attributed to the fact that the various platforms use different .NET runtime ecosystems. This prevents you from writing an assembly for one and runs it on all .NET Runtimes.
Portable Class Library allows you to develop a Class Library that can run for multiple platforms. You can choose a set of platforms for the Portable Class Library while creating it. This choice is represented by the "Profile" identifier and helps in identifying the platforms the Portable Class Library is meant to work with.
The benefits of using this approach are:-
It’s possible to convert a PCL to a .NET Standard project by changing the target of your project to .Net Standard.
This is one of the most frequently asked Xamarin interview questions for freshers in recent times.
While developing apps with Xamarin.Forms, you will find that certain native platform-specific functionalities are not present in the Xamarin.Forms API. This is because of the generic nature of Xamarin.Forms. Xamarin.Forms allow apps to call into platform-specific functionality from shared code. This functionality enables Xamarin.Forms apps to do anything that a native app can do. You need to necessarily define an interface and write platform-specific implementations of that interface in the platform project. Dependency service will find the correct implementation of that interface in the various platform projects. Xamarin.Forms apps need four components to use DependencyService:
The structure of the application is explained by the following diagram:
Custom renderers allow the Generic Xamarin.Forms control to be customized in behavior and look as per the platform they are going to be used on. This enables developers to give a native look and behavior to the otherwise Generic Xamarin.Forms Control.
Xamarin Forms controls are NOT rendered directly on the native platform. Every Xamarin.Forms control has an accompanying renderer for each platform that creates an instance of a native control. The properties from the Xamarin Forms control are translated across to the native control, then the native control is placed in the native layout, which then gets rendered by the platform.
Custom Renderers allow developers to customize the appearance and/or behavior of the control by writing their custom classes. Custom Renderers can be defined to have a custom behavior or appearance for one platform while allowing the default behavior on other platforms or they can be defined for each platform and provide customization for each different platform like iOS, Android, and the Universal Windows Platform (UWP). If instead of changing the complete behavior and appearance only some trivial changes are required then 'Effects' can be used as an alternative.
5 Effects, like Custom Renderers, allow a developer to customize controls for a specific platform. Effects are preferred over Custom Renderers when small styling changes are required instead of a complete layout or behavior change. Custom Effects are created for platform-specific projects by extending the base class PlatformEffect. Once created, they can be attached to the control it is meant for.
Effects don't have any type related information about the control they are attached to and hence if they are specified with a wrong control they should gracefully degrade. Effects are reusable and can be parameterised to extend its reusability.
Eg The sample application demonstrates a Focus Effect that changes the background color of a control when it gains focus.
Xamarin allows two different ways of creating applications, based on the amount of code reusability and customization.
The first approach is the Traditional Native Approach wherein platform-specific apps using Xamarin.iOSiOS and Xamarin.Android can be made. This way of creating apps is generally used when there is a lot of customization specific to the platform is required as it allows direct access to platform-specific APIs. Xamarin.iOS is used for iOS applications and Xamarin.Android is used to create Android applications.
The second approach is creating apps through Xamarin.Forms approach. Xamarin.Forms are used when there is a possibility of reuse of a lot of platform-independent code and the focus is less on custom UI. The platform-independent code is separated and kept in Shared Project or PCL or .NET Standard Library and Platform Specific projects consume this common code by including it.
Pages are Xamarin Forms generic representation of Cross Mobil Application Screens. A Page occupies most or all of a screen and contains a single child.
On IOS, the Page is mapped to ViewController, on Android, it is mapped to somewhat like Activity and on Universal Windows Platform, it is mapped to Page. Pages can be of several types, viz. Master /Detail Page, navigational Page, Carousel Page, Tabbed Page, Template Page, etc.
A Content Page is the most basic type of page which contains the content in a Stak Layout Grid Layout or Scroll View. The content is usually text or images
The Master-Detail Page is divided into two sections: Master and Detail. Master usually contains a list of items or Menu. Clicking on the item would show details about the item on the Detail Page
Navigation Page allows navigating from one page to the next by keeping a stack of all the pages. As the user goes deeper inside the app the pages get stacked one on top of the other and when the user tries to come back to the entry page thee pages are popped out in the reverse order of stacking
Tabbed Image allows viewing multiple child pages across the same page wherein each Tab represents a child page. One child page is active at a time and it is easier to navigate to the other Tab child page by clicking on the Tab
Just like Tabbed page, Carousel Page is also Multipage. It is similar to the gallery. Only the difference is Instead of clicking on the tab, the Carousal allows swiping gestures on the pages to navigate between the multiple child pages
When a user wants to show full mobile screen say for a Game or for showing splash Screen, Template Pages are used. They cover the entire screen area.
FreshMvvm is a super light Mvvm Framework designed specifically for Xamarin.Forms only. It's designed to be Easy, Simple and Flexible. It is easy to learn and uses convention over configuration.
Fresh MVVM deviates a little from MVVM as it uses the concept of Page and PageModel instead of View and ViewModel.
The various features of Fresh MVVM are:
MVVMCross is a .NET cross-platform MVVM framework. It allows making cross-platform solutions, for platforms such as Xamarin.Forms, Xamarin.Android, Xamarin.iOS, Xamarin.Mac, Xamarin.tvOS, UWP, and WPF. It is currently inactive state of development.
MVVM Cross requires the application to be divided into two parts: the Core and the UI. The Core part contains the View Models, Service, Models, and the Business logic whereas the UI parts consist of the different Views and platform-specific code that interacts with the Core. The views are View Screens that contain the graphical content. In addition to Core and UI, the application may contain additional libraries for various functionalities.
The various high-level features that MvvmCross provides are:
The cons of using MVVM Cross are:
MVVM Light is another Framework that allows the creation of Enterprise-Grade apps using the MVVM Architectural pattern on Xamarin. MVVM Light enables developers to create and develop MVVM applications on a variety of platforms like Xamarin.Forms, Xamarin.Android, Xamarin.iOS, UWP, and WPF. It allows you to separate the View from Model and hence right more testable and extensible applications. It is not in active development now. It does not support async commands.
A typical MVVM Light application is divided into the following parts:
MVVM Light advocates the use of a Messenger for loosely-coupled communication everywhere in the app, including data binding, dialogs, and navigation:
This is one of the most frequently asked Xamarin interview questions for experienced in recent times.
XAML(Extensible Application Markup Language) allows developers to define the UI in Xamarin.Forms application using markup instead of code. The Designer allows previewing this UI thereby simplifying the design process.
The Xamarin.Forms pages have markup which has the responsibility of visual design for the UI and associated code to specify some action or logic based on interaction with the UI.
Xamarin.Android additionally supports AXML which is also a markup language specifically made for Xamarin.Android.
The main advantage of using XAML is it provides a clean separation of markup and code, so while the developer can concentrate on the behavior of the application (i.e. the code), the graphic designers can focus on the look and feel of the application. XAML can be compiled, and it takes full advantage of the Longhorn graphics subsystem, helping developers to produce great visual effects. In a XAML file, there is a clear hierarchy of graphical elements and it is easy to understand the GUI design of the app i.e. which element encloses which other elements. The separation of concerns ensures that any changes to the visual aspects of the application may not affect the business logic.
The drawbacks of using XAML are, XAML cannot contain any logic, all the logic has to go into separate code files. It does not directly support conditional processing or loops for repetitive processing of tasks
The lifecycle of an app contains the sequence of methods that are called since the time the app is launched until the time it is in the memory. The Lifecycle methods allow developers to write code for initialization or logic or transition so that the app components are initialized or show a specific behavior as and when they transit from one state to another. The developer may want to save state, initialize graphical components with data or reset apps state or free memory during these App methods.
The various life cycle methods of XamarinForms Apps are:
While writing an application with MVVM, developers specify data bindings in the View Model to bind the UI and the underlying code. Sometimes it may be required that instead of simple properties, the app may have to react to commands initiated by a user that affect something in the View Model. Such commands are generally associated with button clicks of a button or Tap event of a gesture and are handled by the appropriate background handler. These Commands, that implement the ICommand interface, define the operation to be performed when the appropriate Click or Tap is performed. To use the command interface, one has to define a data binding that targets the Command Property of the Button whereas the source is a property in the ViewModel of type ICommand.
Behaviors are a special technique that lets us add functionality to your UI control without having to subclass the control. Behaviors are implemented to code and attached to the controls written in XAML or code. Behaviors interact directly with the APIs exposed by the controls and hence they can be packaged with the control and reused across various applications. Behaviors allow adding new functionality like e.g. an Email Validator to an Entry that accepts Email as user input. Another use case could be a spelling checker with the Entry that helps you correct your spelling while typing. Other typical uses of behaviors are to add an effect to control or to control the control animation.
Behaviors are usually of following types:
Behaviors are written for a specific control type ), and hence, they are supposed to be added only to a compatible control. Attempting to attach a behavior to an incompatible control will result in an exception being thrown.
The Xamarin.Forms Entry is used to specify single-line text input. It is like a TextBox where the user can enter text characters. It, just like the Editor view, supports multiple keyboard types. Entry can also be used as a password field where each character entered is replaced by a * on the Entry thereby hiding the actual characters.
Editor, just like entry is used to enter the text input, the difference being the Editor allows multiple- line input. Editor also has a Tet property that represents the text that is associated with the Editor control. Editor and Entry can be both used to specify placeholder text thereby allowing the developer to give hints with sample text to make it easy for the developer to enter text in a correct format.
Expect to come across this, one of the most important Xamarin interview questions and answers for experienced professionals in Mobile App Development, in your next interviews.
Triggers allow the developer to specify actions declaratively in XAML to change the appearance of controls based on events or property changes. For eg, you may want to change the appearance of a button when it is in pressed state vs when it is not pressed. A trigger can be directly assigned to control.
There are namely four types of triggers:
To provide a seamless experience to users iOS provides metadata to the system in the form of info.plist (information property list file). This metadata is used by the system to identify the app, document types it supports, and to facilitate the launch of apps.
The property list can be accessed by the system at runtime. It containskey-value pairs. These key-value pairs describe the various behaviors and configuration options for the app. For every app, the Xcode provides info.pList files with default key values which can be later edited to suit the needs of the application
The various types of keys defined in info.plist files are:
Xamarin.iOS allows you to use the existing .NET System.IO class to carry out file-related operations on iOS.
The File class provided by .NET lets you create, delete or read files, and the Directory class allows you to create, delete or enumerate the contents of directories. You can additionally also use the Stream classes for finer access to files.
But, iOS imposes certain restrictions regarding what an application can do with the file system to maintain the security and integrity of the file system and prevent malignant apps from creating havoc. It is restricted to mostly access its home directory to read and write files and cannot interfere or read other applications directories. A set of rules apply on iOS to limit an app's access to files, preferences, network resources, hardware, etc.
It is important to understand that the iOS file system is case-sensitive so 'file' and 'File' are interpreted differently on iOS. iOS uses the forward-slash ‘/'as the path separator, so to maintain a common flow, System.IO.Path.Combine is preferred instead of explicitly specifying the path separator.
Sometimes a developer has a requirement to store some basic user data dealing with user settings and app configuration. There are plenty of ways that Xamarin.iOS provides to save this data in your app. One such way is through NSUserDefaults.
The NSUserDefaults class is very much like plist in the sense it stores key-value pairs.
It is not recommended storing anything with sensitive user information (username, password, etc) as these values are saved in a plain text .plist file in the documents directory.
To read from or write to NSUserDefaults, one has to get a reference to it. In the simplest use of NSUserDefaults, this is done via a method that returns a reference to an object capable of interacting with NSUserDefaults's data store.
Xamarin.iOS supports linking with both native C libraries and Objective-C libraries.
For linking with third-party C libraries, it is required that all the libraries be linked statically.
Following are the steps one needs to follow to consume third party C Libraries:
This is a common yet one of the most important interview questions for Xamarin Developer, don't miss this one.
A Service is an application component that allows a user to run long operations that do not require user interaction. Services are broadly classified into Started and Bound Service.
A Started service is one which is invoked by call StartService(). Once started the service can run indefinitely in the background, even after the component that started it is destroyed. Usually, a started service performs a specific operation (like downloading a file) and stops itself. A User-defined Started Service can be created by either extending the Service class or by extending the Intent Service. An Intent Service is a special type of Service which stops itself automatically after completing the task assigned.
A Bound Service is created when the application component calls BindService() to bind to a service. Bound Service is like a Client-server interface that allows components to interact with the service, send requests, get results, etc. A Bound service can be accessed by the components within an application and also by components residing in other applications (if it is exported/exposed). Bound Services only keep running till they have a client associated with it. When all clients Unbind the service the service stops
A staple in Xamarin practical interview questions and answers, be prepared to answer this one using your hands-on experience as mentioned.
AsyncTask is a facility given by Android for executing operations in a background thread without having to manually handle thread creation or execution
Aynctask has following important callback methods:
Asynctasks should always be created and loaded on the GUI thread. They cannot be started more than once.
A Pending Intent wraps another intent object. A Pending Intent means the intent that is being enclosed may not be executed now but some time in the future. Pending Intent can be passed on to a foreign application thereby granting that app the right to perform the operation represented by the intent
A PendingIntent itself is a token referencing the original content of the intent viz the action, data, categories, etc. Even if the owning app is killed by the system, PendingIntent can still be executed and it will again bring back the app back in memory. An app after providing the PendingIntent to a foreign app can cancel the need be. PendingIntent can be created for an Activity(through GetActivity() or Broadcast ( via GetBroadcast Method or service (via GetService() method).
Unlike Android, iOS does not allow users to directly install third-party apps. Only those apps that are signed by Apple can only be installed by the iOS users. The provisioning profile is a link between the Developer of the app (his Developer Account) and the Device on which it is being used. The provisioning profile is downloaded from the developer account and the entire bundle is code-signed by the iOS. A Development Provisioning Profile must be installed on each device on which the developer wishes to run his application. If the information in the provisioning profile doesn't match certain criteria, the app won't launch.
A provisioning profile necessarily consists of:
A staple in Xamarin developer interview questions with answers, be prepared to answer this one using your hands-on experience. This is also one of the top interview questions to ask a Xamarin Developer.
The Navigation Page in Xamarin.Forms provide a Hierarchical Navigation to the user. The Navigation is implemented via a stack on the principle of Last In First Out or LIFO. When a user opens the app a default page sits at the top of the stack of the Navigation system. As the user navigates to a new page, the new page gets pushed onto the Navigation stack and becomes the active page.
In Hierarchical Navigation, NavigationPage Class is used to Navigate through a stack of ContentPage Objects. The Navigation Page is the root Page and content Pages are the child Pages on top of it.
The layout of the NavigationPage is platform-dependent i.e. depending on the platform on which it is displayed it has a different appearance:
Mobile gestures are the movements made by a user to perform a specific action on a control within a mobile interface majorly through fingers(tap, swipe, drag, slide, etc.). The various Gestures supported by Xamarin.Forms are:
This, along with other Xamarin questions and answers, is a regular feature in Xamarin interviews, be ready to tackle it with the approach mentioned.
Xamarin is a software company based in San Francisco and was founded by the same engineers who created the free, open-sourced project named Mono, Xamarin.Android, and Xamarin.iOS. All these created implementations of the Common Language Infrastructure (CLI) and Common Language Specifications, ie. Microsoft .Net.
Xamarin is a coder’s wish come true, allowing features like enabling coders to use C# to write their apps for Windows, Android, and iOS applications, sharing codes over multiple platforms develop the application’s user interface with the usage of the Model/View/Controller pattern, build native UIs, has API integration, and not to forget having a huge community and community for end-users. As per claims by Xamarin, the Xamarin products were the most used ones amongst users in April 2017, the figures state over 1.4 million across 120 countries around the world.
On February 24, 2016, Microsoft signed an officially conclusive agreement with Xamarin for acquiring rights.
Xamarin proves itself as an all-in-one solution to mobile devops, enabling users to use just a single tool to freely build, test, develop, distribute, and monitor native mobile apps across many platforms. Simply put, it saves one-third of the time, effort, and money for mobile application development.
Going by the way it allows a smooth transition between various platforms and in process, reducing the gaps between them, Xamarin is moving into a bright future which is aided by the fact that Microsoft acquired it and is free as well.
Because of Xamarin’s ability to flexible across multiple platforms, there are wide varieties of jobs in software development and the salaries offered will not disappoint you as well. According to payscale.com, on average, software developers skilled with Xamarin earn $ 71,993 per annum, going as high as $103,000. You may also work as a Mobile Applications Developer with Xamarin skills and the average annual salary is 72,901 with the highest pay reaching up to $101,014. For senior software engineers with Xamarin skills, the average annual salary is $105.393, going as high as $ 114,000.
The major companies hiring Xamarin software developers are Microsoft Corp., Wipro, NIC Inc., Rush University Medical Center, Calabrio, and ScienceSoft USA
So, it is evidently a great prospect to be a software developer with Xamarin skillset. What you need to successfully clear any Xamarin interview is to maintain focus and follow a systematic path to answer all the Xamarin interview questions. But how would you do that? We are here to help you.
We are well aware of what a candidate goes through at an interview. Many interview questions can make one tensed and nervous, resulting in answering them incorrectly. However, our experts have systematically compiled a set of Xamarin interview questions that will not only guide you to know how you will answer any possible question in a clear manner without any confusion but also give you an edge over the other candidates to excel in any Xamarin job interview.
So why wait any longer? Go through our Xamarin interview questions to crack any Xamarin developer interview and get your career going full steam ahead!