Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Xamarin Mobile Platform

782 views

Published on

Slides from presentation given at Poznań Android Developer Group Meetup #3 - December 11, 2014

Published in: Software
  • Be the first to comment

  • Be the first to like this

Introduction to Xamarin Mobile Platform

  1. 1. Dominik Minta dominik@minta.it Poznań Android Developer Group Meetup #3
  2. 2. Problem – typical application  Multiplatform – Android, iOS, Windows Phone  Tasks: - downloading, parsing and storing data (JSON, XML, images) from webservices in local database (SQL) - filtering and presenting data to user in a convenient form (lists, maps) - sharing content with social network (Facebook, Twitter etc.) - utilizing location services - taking a picture with camera  Some features are available offline
  3. 3. Typical solutions Native applications  Full access to platform capabilities (camera, GPS, accelerometer etc.)  Native UI  High performance (native code, hardware access)  Separate UI design and source code for each platform  Different libraries for the same task (downloading and displaying images, social network integration, handling network protocols etc.)  Developers must be familiar with each supported platform Hybrid applications  Many frameworks to choose from (Cordova/PhoneGap, ionic, Titanium, Sencha Touch…)  Single code base  Low entry level (HTML, CSS, JS)  Can be extended using native code  Partial access to platform capabilities out-of-the-box  HTML5 UI  Poor performance and responsiveness for extensive UI  Problems with webview on different platforms  JS debugging = pain
  4. 4. Xamarin Mobile Platform  Shared code on each platform (also UI!)  Full native API access  Native performance  Modern programming language – C# (F# also supported)  Multiplatform libraries  Works with existing libraries  Xamarin Studio multiplatformIDE (Linux, MacOS X, Windows)  Visual Studio plugin  Good documentation, community and support  http://xamarin.com
  5. 5. Applications built with Xamarin  Bastion  Calca  Draw a Stickman: EPIC  iCircuit  Infinite Flight  Legimi  Nokia MixRadio  Rdio  TouchDraw  Vezma Sources: http://www.monogame.net/showcase/ http://icircuitapp.com/ http://elevenworks.com/
  6. 6.  „Spotify for ebooks”  Ebook readers for Android, iOS, Windows Phone 7+, Windows 8 and Onyx e-ink devices  First app was running on Linux-based e-ink device using Mono runtime (2009)  Shared part of logic code (webservice communication, epub handling, DRM, local database, utility classes)  Native UI Source: legimi.com
  7. 7. How Xamarin works on Android?  Applications and libraries are compiled to .NET bytecode (Intermediate Language) which is stored in .NET assemblies (DLL)  Unused code is removed  Generated application package (APK) is shipped with Mono Virtual Machine (native library for each supported platform – ARM, x86)  When user runs an application, Mono JIT (Just-in-Time) compiler compiles IL to native code and executes it  Mono runtime handles memory allocation, garbage collection and serves as a bridge between user code and native API
  8. 8. Why you should learn C#?  var keyword  Properties  Events  Operator overloading  Indexers  Partial classes  „True” generics  Value types  Object/collection initializers  Extension methods  Linq  Task-based parallelism  Access to powerful Base Class Library
  9. 9. var keyword  Java VeryLongClassName<VeryLongParameterName> variable = new VeryLongClassName<VeryLongParameterName>();  C# var variable = new VeryLongClassName<VeryLongParameterName>(); var hello = „Hello Android”;
  10. 10. Properties  Java private int foo; public int getFoo() { return foo; } protected void setFoo(int foo) { this.foo = foo; }  C# public int Foo { get; protected set; }
  11. 11. Events  Java (Android) Listeners button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { label.setText(„Hello, Android); } }  C# button.Click += (s, e) => { label.Text = „Hello, Android”; }; Listeners are supported but they must be implemented as a part of named class
  12. 12. Object/collection initializers  Java Button button = new Button(this); button.setText(„Click me”); button.setFoo(„abc”); button.setBar(123);  C# Button button = new Button(this) { Text = „Click me”, Foo = „abc”, Bar = 123 };
  13. 13. Extension methods  Add methods to object instances without inheritance class SealedClassExtensions { public static void ExtensionMethod(this SealedClass instance) { // implementation } } SealedClass instance = new SealedClass(); instance.ExtensionMethod(); or SealedClassExtensions.ExtensionMethod(instance);
  14. 14. Linq – Language Integrated Query class User { … public int Age { get; set; } public string City { get; set; } } class City { … public string Name { get; set; } public string PostalCode { get; set; } } List<User> users = LoadUsers(); List<City> cities = LoadCities(); var filteredUsers = from user in users join city in cities on user.City equals city.Name where user.Age >= 18 orderby user.Age descending select new { Age = user.Age, City = user.City, PostalCode = city.PostalCode };  Different data sources are supported (collections, XML, databases)
  15. 15. Task-based parallelism async Task<ParsedResult> DownloadAndParseDataAsync() { Task<string> downloadTask = DownloadDataAsync(); IndependentMethod(); string textData = await downloadTask(); ParsedResult result = ParseData(textData); return result; }  async and await keywords  Async task should have Async method name suffix and must return Task or Task<T> result
  16. 16. Base Class Library  System – basic reference and value types, array handling, math functions  System.Collections*– generic & nongeneric collections  System.ComponentModel* - attributes, type converters, data binding  System.Data* - database access, SQLite support  System.Diagnostics – logging, tracing, interaction with processes  System.Globalization – culture support  System.IO – streams, file system, compression  System.Json – JSON processing  System.Linq – Linq support  System.Net – support for the most popular network protocols  System.Numerics –BigInteger, complex numbers  System.Reflection – operations on assembly metadata  System.Runtime - serialization  System.Text – encoding utils, regexp  System.Threading – multithreaded programming  System.Xml*– XML processing
  17. 17. Xamarin Forms  Native UI using single code base  UI components (pages, layouts, controls, animations)  Write custom components or extend existing  Views defined in C# code or XAML  Binding and MVVM support Source: http://xamarin.com/forms
  18. 18. MVVM pattern  Model – data source  View – native UI (no code behind)  ViewModel - logic  Uses data binding  Separate UI and logic  Easy testing  MvvmCross, MVVM Light
  19. 19. Other Xamarin products  Test Cloud – run apps on real Android devices in the cloud - test scripts written using Calabash framework with Cucumber (Ruby) or in C# - reports with logs, screenshots and performance metrics - integration with CI systems (Jenkins, TeamCity…)  Insights - track exceptions and crashes in apps - find out which sequence of events lead to the crash - online backend with issues browser and statistics  University - live online classes, certification exams
  20. 20. Library sources  Codeplex (http://www.codeplex.com)  Github (https://github.com)  Nuget (https://www.nuget.org)  Component Store (https://components.xamarin.com)
  21. 21. Gamedev  MonoGame – multiplatform MS XNA port (http://www.monogame.net)  Cocos2D-XNA – Cocos2D C# port (http://www.cocos2dxna.com)  CocosSharp - Cocos2D-XNA fork with better API (https://github.com/mono/CocosSharp)  Delta Engine - http://deltaengine.net  WaveEngine - http://waveengine.net
  22. 22. Disadvantages  Developer must be familiar with C#, .NET and target platforms  Generated APK size  Native platform bugs + Xamarin bugs = new bugs  Cannot use C# code in native projects (C++, Java, Objective C, Swift)  Mac device is required for iOS apps, Windows 8 device is required for Windows Phone apps
  23. 23. Pricing  Starter – free but very limited (app size, cannot compile apps using Xamarin Forms)  Indie - $25/month or $300/year, free for students   Business - $83/month or $999/year, supports Visual Studio  Enterprise - $158/month or $1899/year, additional components and support  Special offer for startups and small companies
  24. 24. Questions?

×