SlideShare a Scribd company logo
1 of 24
Dominik Minta 
dominik@minta.it 
Poznań Android Developer Group Meetup #3
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
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
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
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/
 „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
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
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
var keyword 
 Java 
VeryLongClassName<VeryLongParameterName> variable 
= new VeryLongClassName<VeryLongParameterName>(); 
 C# 
var variable = new VeryLongClassName<VeryLongParameterName>(); 
var hello = „Hello Android”;
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; 
}
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
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 
};
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);
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)
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
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
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
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
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
Library sources 
 Codeplex (http://www.codeplex.com) 
 Github (https://github.com) 
 Nuget (https://www.nuget.org) 
 Component Store (https://components.xamarin.com)
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
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
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
Questions?

More Related Content

Similar to Build Cross-Platform Apps with Shared C# Code

Android Overview (Karlsruhe VKSI)
Android Overview (Karlsruhe VKSI)Android Overview (Karlsruhe VKSI)
Android Overview (Karlsruhe VKSI)Lars Vogel
 
Porting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindPorting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindBeMyApp
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastBartosz Kosarzycki
 
Software Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & SpoofaxSoftware Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & SpoofaxEelco Visser
 
Going Desktop with Electron
Going Desktop with ElectronGoing Desktop with Electron
Going Desktop with ElectronLeo Lindhorst
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyUlrich Krause
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroMohammad Shaker
 
Dot netsupport in alpha five v11 coming soon
Dot netsupport in alpha five v11 coming soonDot netsupport in alpha five v11 coming soon
Dot netsupport in alpha five v11 coming soonRichard Rabins
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Android101 - Intro and Basics
Android101 - Intro and BasicsAndroid101 - Intro and Basics
Android101 - Intro and Basicsjromero1214
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first appAlessio Ricco
 
Playing with parse.com
Playing with parse.comPlaying with parse.com
Playing with parse.comJUG Genova
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioGünter Obiltschnig
 

Similar to Build Cross-Platform Apps with Shared C# Code (20)

Lecture1
Lecture1Lecture1
Lecture1
 
PPT Companion to Android
PPT Companion to AndroidPPT Companion to Android
PPT Companion to Android
 
Android Overview (Karlsruhe VKSI)
Android Overview (Karlsruhe VKSI)Android Overview (Karlsruhe VKSI)
Android Overview (Karlsruhe VKSI)
 
Porting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindPorting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mind
 
React native
React nativeReact native
React native
 
Intro to Android Programming
Intro to Android ProgrammingIntro to Android Programming
Intro to Android Programming
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
Software Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & SpoofaxSoftware Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & Spoofax
 
Going Desktop with Electron
Going Desktop with ElectronGoing Desktop with Electron
Going Desktop with Electron
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
Dot netsupport in alpha five v11 coming soon
Dot netsupport in alpha five v11 coming soonDot netsupport in alpha five v11 coming soon
Dot netsupport in alpha five v11 coming soon
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Cluster Computing Web2 Sept2009
Cluster Computing Web2 Sept2009Cluster Computing Web2 Sept2009
Cluster Computing Web2 Sept2009
 
Android101 - Intro and Basics
Android101 - Intro and BasicsAndroid101 - Intro and Basics
Android101 - Intro and Basics
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first app
 
Playing with parse.com
Playing with parse.comPlaying with parse.com
Playing with parse.com
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.io
 
Docker practical solutions
Docker practical solutionsDocker practical solutions
Docker practical solutions
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

Build Cross-Platform Apps with Shared C# Code

  • 1. Dominik Minta dominik@minta.it Poznań Android Developer Group Meetup #3
  • 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. 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. 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. 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.  „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. 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. 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. var keyword  Java VeryLongClassName<VeryLongParameterName> variable = new VeryLongClassName<VeryLongParameterName>();  C# var variable = new VeryLongClassName<VeryLongParameterName>(); var hello = „Hello Android”;
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Library sources  Codeplex (http://www.codeplex.com)  Github (https://github.com)  Nuget (https://www.nuget.org)  Component Store (https://components.xamarin.com)
  • 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. 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. 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