As a complete beginner to Xamarin and new entrant to mobile app development, I have some questions about Xamarin and about the way it works which I was not able to find on the internet
How does Xamarin Cross-platform actually work? Is it any use? I was told Xamarin told Xamarin is a cross-platform mobile development solution, but when I Start off, I see it actually encourages you to create separate projects for iOS and Android. I understand that is to give us more power and there is always Xamarin Forms if we want cross-platform UI. In that case, however, I would expect the Portable Class libraries to handle all the backend logic while the native projects are used only for the UI. But when I started out, the most basic library for accessing mobile functionality (Xamarin.Mobile), is not compatible with PCL. What is the use of PCL even in that case?
How are cross-platform apps generally made in Xamarin? What is the role of the PCL and how do we get it to do cross-platform stuff?
Is there no pre-built Xamarin API which allows to do most mobile-related stuff platform independently? Seems we have to download new libraries from nuGet for every little thing we want to do which is quite painful
I hate to ask this. But is the only real advantage of Xamarin the fact that we can code in C# instead of native languages? What I was expecting is actual cross-platform shared code-base. If unity can do it, why can Xamarin not do it?
As someone who's worked with Xamarin (certified) for more than 2 years I will try to answer your questions:
1) Xamarin is a .NET framework that compiles to native code for both platforms. 2 years ago you'd create projects for every 'type' of app you built (Android, iOS, etcetera). In practise this meant you writing Activities for android (in the .NET way of doing things, but with the exact same native android types) and UIViewControllers for iOS. Xamarin.Forms has been out for a while and is a solution that will allow you to share UI Code as well as Business logic.
2) Depending on the app, one chooses either Xamarin.Forms or the native route. In case of the native route you'd create views for every platform (Android AXML and iOS Storyboarding). Additionally a PCL would be added containing all the business logic. This way you can call
var authResult = AuthService.Login(username,password);
var settings = SettingsService.GetUserLocalDbSettings();
from both iOS and Android, and the business logic for logging someone in - only has to be written once. Xamarin.Forms allows you to also share UI, by building XAML-layouts in the Xamarin.Forms project. These get transformed to the right screen type in either OS. Note: This only works properly with simple layouts (think lists, tabs etcetera). Complex layouts take way more time in forms to the point you switch to native.
3) Xamarin is only the framework allowing you to write .NET for these platforms. There's a lot of plugins available (e.g. Connectivity check) that are available. Install them in your native projects AND the PCL, and you'll be able to check whether the app has connectivity from within the PCL, or not). Xamarin is the hammer, Nuget offers the nails.
4) You can share a lot of code (PCL). My honest experience though is that most of the time you'll be building layouts (views) for both platforms. The business logic (signing in, saving items to a SQLite database) costs the least time to build. UI / design however,....requires a lot more patience. So YES you can share all business logic (as far as the used libraries respect the PCL profile).
5) Protip: Xamarin offers some free university training since they have been part of Microsoft.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With