InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Methods to Share Code between Cross-Platform Applications on Xamarin |
|
Answer» 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:
Disadvantage
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:-
Disadvantages:- 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:-
Disadvantages:-
It’s possible to convert a PCL to a .NET Standard project by changing the target of your project to .Net Standard. |
|
| 2. |
How to do Xamarin.Android applications work? |
|
Answer» 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. |
|