introduction to xamarin mobile platform
Post on 16-Jul-2015
289 Views
Preview:
TRANSCRIPT
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 convenientform (lists, maps)- sharing content with social network (Facebook, Twitter etc.)- utilizing location services- taking a picture with camera
Some features are available offline
Typical solutionsNative applications
Full access to platform capabilities(camera, GPS, accelerometer etc.)
Native UI
High performance (native code, hardware access)
Separate UI design and source codefor each platform
Different libraries for the same task(downloading and displayingimages, social network integration, handling network protocols etc.)
Developers must be familiar witheach 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 differentplatforms
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 multiplatform IDE (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
VezmaSources: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 usingMono runtime (2009)
Shared part of logic code (webservicecommunication, epub handling,DRM, local database, utility classes)
Native UISource: 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 withMono Virtual Machine (native library for each supportedplatform – 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, garbagecollection 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() {
@Overridepublic void onClick(View v){label.setText(„Hello, Android);
} }
C#
button.Click += (s, e) =>
{label.Text = „Hello, Android”;
};
Listeners are supportedbut 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 Queryclass 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 usersjoin city in citieson user.City equals city.Namewhere user.Age >= 18orderby user.Age descendingselect new {
Age = user.Age,City = user.City,PostalCode = city.PostalCode
};
Different data sources aresupported (collections, XML, databases)
Task-based parallelismasync 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 supportSource: 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 withCucumber (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 deviceis 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, additionalcomponents and support
Special offer for startups and small companies
top related