SlideShare uma empresa Scribd logo
1 de 35
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin - Under the Bridge
Microsoft&Xamarin MVP, Xamarin Certified Mobile Developer
CTO Mahiz S.r.l.
dan.ardelean@mahiz.it Twitter: @danardelean
Dan Ardelean
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Many thanks to our sponsors & partners!
GOLD
SILVER
PARTNERS
PLATINUM
POWERED BY
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
XAMARIN
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
XAMARIN
C#/F#
Visual Studio
Xamarin Studio
Black Magic
Native
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
iOS Native Applications
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
iOS Native Application
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO XCODE
SINGLE VIEW APPLICATION
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
C# to Objective-C world
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin iOS Compilation
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Expose Objectve-C to C# using Selectors
• objc_msgSend functions
Selectors
-[NSString sizeWithFont:forWidth:lineBreakMode:]
sizeWithFont Selector:
- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode
Objective-C declaration:
CGSize objc_msgSend(IntPtr target, IntPtr selector, IntPtr font, nfloat width, UILineBreakMode mode);
objc_msgSend
[DllImport (Constants.ObjectiveCLibrary,EntryPoint="objc_msgSend")]
static extern CGSize cgsize_objc_msgSend_IntPtr_float_int ( IntPtr target, IntPtr selector, IntPtr font,
nfloat width, UILineBreakMode mode);
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Expose Objectve-C to C# using Selectors
• objc_msgSend functions
Selectors
NSString target = ...
Selector selector = new Selector ("sizeWithFont:forWidth:lineBreakMode:");
UIFont font = ...
nfloat width = ...
UILineBreakMode mode = ...
CGSize size = cgsize_objc_msgSend_IntPtr_float_int( target.Handle, selector.Handle, font == null ?
IntPtr.Zero : font.Handle, width, mode);
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Expose Managed Code to Objective-C
Registrars
[Register]
class MyViewController : UIViewController{
[Export ("myFunc")]
public void MyFunc () { }
}
C# (Managed Code)
Objective-C
@interface MyViewController : UIViewController { }
-(void)myFunc;
@end
@implementation
MyViewController {}
-(void) myFunc
{ /* code to call the managed MyViewController.MyFunc method */
}
@end
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO XAMARIN IOS
Single View Application
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin.iOS creates a managed wrapper, called a peer
object, for every native object accessed by the
Xamarin.iOS runtime
Peer wrapper objects
UIKit.UIButton
(peer object)
[UIButton]
(native object)IntPtrHandle
Allocated by
Xamarin.iOS
and collected by the
GC
Allocated by the iOS
runtime
and reference counted
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Peer object increment the retain count; it is released
when the managed peer is disposed or finalized
Memory allocation Xamarin.iOS
1
GC
Collect
[brelease] 0
b =null;
b.Dispose(); [brelease] 0
var b = new UIButton(...) [[UIButton alloc]init]
…
or
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Monitoring memory allocations
Memory
Analysis
(Heap shot)
Instrument
s
Androi
d
Device
Monitor
Xamarin
Profiler
VS
Profiler
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO MEMORY ALLOCATION
Single View Application
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Prefer full delegate methods over lambdas – it makes it
easier to see and understand strong references
Call Dispose() to release native resources immediately (vs.
waiting ona GC) when you are finished with a peer
wrapper
Always unsubscribe from events you manually wire up;
alternatively, use the Storyboard to connect events which
can then be cleaned up automatically
Xamarin.iOS Tips
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Android native application
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Android Native Compilation
.dexfilesJava
compile
r
Android
dex
compiler
Java
bytecodes
Dalvik
bytecodes
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Android Native Compilation
.dexfiles
Resources
(e.g.
images)
.apkfileAndroid
apkbuilde
r
The .apkfile contains
all the app's assets
and is ready to run
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Android Native Execution
Bytecodes are compiled to
native code at installation
(called Ahead-of-Time or
AOT)
MyApp.apk
Android
Runtime
(ART)
Apps run in their own
process with their own
copy of the ART Virtual
Machine
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO ANDROID STUDIO
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin.Android Architecture
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin.Android Compilation
assemblyC#
compiler
IL and
metadata
Linke
r
Monoassemblies
yourassemblies
Monoassemblies
(filtered)
Determines which class members are used in
your app and includes only those members in
the output
yourassemblies
(filtered)
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin.Android Compilation
Mono
Runtime
The Xamarin build tools
add the Mono VM to
your application
package
.apkfileAndroid
apkbuilde
r
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO XAMARIN.ANDROID
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin.Android GC Process
GC
Collect
Can
collect
object?
Is
Peer
Object
?
Ye
s
Replace JNI
handle with
Weak Handle
Ye
s
Force Android GC
JNI
handle
collected
?
Collect object
No
Ye
s
Replace JNI
weak handle
with strong
handle reference
NoPeer
object
kept alive
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Integration between Xamarin GC and JVM GC is
performed through a native extension called the GC
Bridge
GC Bridge
Xamarin
Manage
d
Memory
Android
Manage
d
Memory
GC
Bridge
Process
Memor
y
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• GC_ messages provide details about bridge and
collection times
Monitoring GC Performance
GC_MAJOR:(Minor allowance) pause 29.11ms, total 29.35ms, bridge 0.15msmajor
4048K/0K los 2766K/0K
Lower pause, bridge and total times are
preferred
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• C# objects must be boxed to create a JVM
representation of the object; intrinsic types (strings,
numeric values and dates) are all special cased
Xamarin and the JAVA VM
C#
Object
Java
Object
ArrayAdapter<Tweet>
ArrayAdapter
ArrayLi
stTweet Tweet Tweet Tweet
Tweet Tweet Tweet Tweet
ListView
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• Instead, do as much as possible in either C# or Java,
interop is expensive
Stay in your yard
C# Object
Java
Object
TweetAdapter
List<Tweet>
Tweet Tweet Tweet Tweet
ListView
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Should call Dispose() to release the native resources
immediately (vs waiting on a GC) when you are finished
with a peer wrapper
Avoid placing a large numbers of references in peer
objects, remember GC is more expensive for these special
types
Avoid passing pure C# custom types into Java APIs if
possible
Xamarin.Android Tips
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Xamarin
Process
Memory
UIView
UIImage
MKMapVie
w
...
Activity
Intent
TextView
...
Managed
Memory
C# and .NET
objects are
allocated here
- this is all GC
knows about
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Q & A

Mais conteúdo relacionado

Mais procurados

4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트 4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
양 한빛
 
SignalR Intro + WPDev integration @ Codetock
SignalR Intro + WPDev integration @ CodetockSignalR Intro + WPDev integration @ Codetock
SignalR Intro + WPDev integration @ Codetock
Sam Basu
 

Mais procurados (20)

New NeXt for Advanced Developers
New NeXt for Advanced DevelopersNew NeXt for Advanced Developers
New NeXt for Advanced Developers
 
Hands on-intro to Node-RED
Hands on-intro to Node-REDHands on-intro to Node-RED
Hands on-intro to Node-RED
 
Use Cognitive Capabilities with iOS Core ML
Use Cognitive Capabilities with iOS Core MLUse Cognitive Capabilities with iOS Core ML
Use Cognitive Capabilities with iOS Core ML
 
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & CloudantBuild Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
Build Scalable Internet of Things Apps using Cloud Foundry, Bluemix & Cloudant
 
Developing i phone, android and windows phone 7 applications with c#
Developing i phone, android and windows phone 7 applications with c#Developing i phone, android and windows phone 7 applications with c#
Developing i phone, android and windows phone 7 applications with c#
 
Mobile Testing Challenges at Zalando Tech
Mobile Testing Challenges at Zalando TechMobile Testing Challenges at Zalando Tech
Mobile Testing Challenges at Zalando Tech
 
AppliFire - Low Code Rapid Application Development Platform
AppliFire - Low Code Rapid Application Development PlatformAppliFire - Low Code Rapid Application Development Platform
AppliFire - Low Code Rapid Application Development Platform
 
Native iOS and Android Development with Xamarin
Native iOS and Android Development with XamarinNative iOS and Android Development with Xamarin
Native iOS and Android Development with Xamarin
 
Azure App Service Helpers
Azure App Service HelpersAzure App Service Helpers
Azure App Service Helpers
 
apidays LIVE Australia 2020 - From micro to macro-coordination through domain...
apidays LIVE Australia 2020 - From micro to macro-coordination through domain...apidays LIVE Australia 2020 - From micro to macro-coordination through domain...
apidays LIVE Australia 2020 - From micro to macro-coordination through domain...
 
Seattle Mobile .NET User Group - Nov. 13th 2019
Seattle Mobile .NET User Group - Nov. 13th 2019Seattle Mobile .NET User Group - Nov. 13th 2019
Seattle Mobile .NET User Group - Nov. 13th 2019
 
4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트 4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
4. RTFM, 나는프로그래머다 Meetup 2016 / 한국마이크로소프트 김명신 기술 에반젤리스트
 
Xamarin: The Future of App Development
Xamarin: The Future of App DevelopmentXamarin: The Future of App Development
Xamarin: The Future of App Development
 
Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++
 
Xamarin.forms Shell + Navigation
Xamarin.forms Shell + NavigationXamarin.forms Shell + Navigation
Xamarin.forms Shell + Navigation
 
Creating Apps with .NET MAUI
Creating Apps with .NET MAUICreating Apps with .NET MAUI
Creating Apps with .NET MAUI
 
SignalR Intro + WPDev integration @ Codetock
SignalR Intro + WPDev integration @ CodetockSignalR Intro + WPDev integration @ Codetock
SignalR Intro + WPDev integration @ Codetock
 
Cloud Aware Large Scale Distributed SOA
Cloud Aware Large Scale Distributed SOACloud Aware Large Scale Distributed SOA
Cloud Aware Large Scale Distributed SOA
 
Mobile development with visual studio
Mobile development with visual studioMobile development with visual studio
Mobile development with visual studio
 
ML Kit , Cloud FF GDSC MESCOE.pdf
ML Kit , Cloud FF GDSC MESCOE.pdfML Kit , Cloud FF GDSC MESCOE.pdf
ML Kit , Cloud FF GDSC MESCOE.pdf
 

Semelhante a Xamarin - Under the bridge

ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp
 
ITCamp 2013 - Petru Jucovschi - Application ecosystems
ITCamp 2013 - Petru Jucovschi - Application ecosystemsITCamp 2013 - Petru Jucovschi - Application ecosystems
ITCamp 2013 - Petru Jucovschi - Application ecosystems
ITCamp
 

Semelhante a Xamarin - Under the bridge (20)

The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
 
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
 
CI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App CenterCI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App Center
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
 
Azure Microservices in Practice - Radu Vunvulea
Azure Microservices in Practice - Radu VunvuleaAzure Microservices in Practice - Radu Vunvulea
Azure Microservices in Practice - Radu Vunvulea
 
Azure tales: a real world CQRS and ES Deep Dive - Andrea Saltarello
Azure tales: a real world CQRS and ES Deep Dive - Andrea SaltarelloAzure tales: a real world CQRS and ES Deep Dive - Andrea Saltarello
Azure tales: a real world CQRS and ES Deep Dive - Andrea Saltarello
 
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
 
ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...
ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...
ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...
 
‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure
 
Everyone Loves Docker Containers Before They Understand Docker Containers - A...
Everyone Loves Docker Containers Before They Understand Docker Containers - A...Everyone Loves Docker Containers Before They Understand Docker Containers - A...
Everyone Loves Docker Containers Before They Understand Docker Containers - A...
 
Azure SQL Database From A Developer's Perspective - Alex Mang
Azure SQL Database From A Developer's Perspective - Alex MangAzure SQL Database From A Developer's Perspective - Alex Mang
Azure SQL Database From A Developer's Perspective - Alex Mang
 
How # (sharp) is Your Katana (Ciprian Jichici)
How # (sharp) is Your Katana (Ciprian Jichici)How # (sharp) is Your Katana (Ciprian Jichici)
How # (sharp) is Your Katana (Ciprian Jichici)
 
BUILD with Microsoft - Radu Stefan
 BUILD with Microsoft - Radu Stefan BUILD with Microsoft - Radu Stefan
BUILD with Microsoft - Radu Stefan
 
A new world of possibilities for contextual awareness with beacons - Dan Arde...
A new world of possibilities for contextual awareness with beacons - Dan Arde...A new world of possibilities for contextual awareness with beacons - Dan Arde...
A new world of possibilities for contextual awareness with beacons - Dan Arde...
 
A new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beaconsA new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beacons
 
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
 
ITCamp 2013 - Petru Jucovschi - Application ecosystems
ITCamp 2013 - Petru Jucovschi - Application ecosystemsITCamp 2013 - Petru Jucovschi - Application ecosystems
ITCamp 2013 - Petru Jucovschi - Application ecosystems
 

Mais de Dan Ardelean

Ciclo di vita di una applicazione Windows Phone Store
Ciclo di vita di una applicazione Windows Phone StoreCiclo di vita di una applicazione Windows Phone Store
Ciclo di vita di una applicazione Windows Phone Store
Dan Ardelean
 

Mais de Dan Ardelean (20)

CI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenterCI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenter
 
Visual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devsVisual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devs
 
Desarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .netDesarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .net
 
Xamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile developmentXamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile development
 
Xamarin.Forms a different approach to cross platform natove mobile development
Xamarin.Forms a different approach to cross platform natove mobile developmentXamarin.Forms a different approach to cross platform natove mobile development
Xamarin.Forms a different approach to cross platform natove mobile development
 
Xamarin - why not ?
Xamarin -  why not ?Xamarin -  why not ?
Xamarin - why not ?
 
Share more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class LibrariesShare more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class Libraries
 
iBeacons for everyone
iBeacons for everyoneiBeacons for everyone
iBeacons for everyone
 
Xamarin Dev Days 2016 introduction to xamarin
Xamarin Dev Days 2016   introduction to xamarinXamarin Dev Days 2016   introduction to xamarin
Xamarin Dev Days 2016 introduction to xamarin
 
C sharp day 2015 c# patterns- cross-platform
C sharp day 2015   c# patterns- cross-platform  C sharp day 2015   c# patterns- cross-platform
C sharp day 2015 c# patterns- cross-platform
 
Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10
 
Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)
 
Community Days 2015 Introduzione a Xamarin
Community Days 2015  Introduzione a XamarinCommunity Days 2015  Introduzione a Xamarin
Community Days 2015 Introduzione a Xamarin
 
Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#
 
WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1
 
Bluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor CoreBluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor Core
 
Introduction to Xamarin 3
Introduction to Xamarin 3Introduction to Xamarin 3
Introduction to Xamarin 3
 
Developing for Windows Phone 8.1
Developing for Windows Phone 8.1Developing for Windows Phone 8.1
Developing for Windows Phone 8.1
 
Ciclo di vita di una applicazione Windows Phone Store
Ciclo di vita di una applicazione Windows Phone StoreCiclo di vita di una applicazione Windows Phone Store
Ciclo di vita di una applicazione Windows Phone Store
 
Design and develop cross-platform mobile apps using MVVMCross
Design and develop cross-platform mobile apps using MVVMCrossDesign and develop cross-platform mobile apps using MVVMCross
Design and develop cross-platform mobile apps using MVVMCross
 

Último

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Último (6)

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 

Xamarin - Under the bridge

  • 1. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin - Under the Bridge Microsoft&Xamarin MVP, Xamarin Certified Mobile Developer CTO Mahiz S.r.l. dan.ardelean@mahiz.it Twitter: @danardelean Dan Ardelean
  • 2. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  • 3. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals XAMARIN
  • 4. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals XAMARIN C#/F# Visual Studio Xamarin Studio Black Magic Native
  • 5. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals iOS Native Applications
  • 6. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals iOS Native Application
  • 7. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO XCODE SINGLE VIEW APPLICATION
  • 8. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals C# to Objective-C world
  • 9. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin iOS Compilation
  • 10. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Expose Objectve-C to C# using Selectors • objc_msgSend functions Selectors -[NSString sizeWithFont:forWidth:lineBreakMode:] sizeWithFont Selector: - (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode Objective-C declaration: CGSize objc_msgSend(IntPtr target, IntPtr selector, IntPtr font, nfloat width, UILineBreakMode mode); objc_msgSend [DllImport (Constants.ObjectiveCLibrary,EntryPoint="objc_msgSend")] static extern CGSize cgsize_objc_msgSend_IntPtr_float_int ( IntPtr target, IntPtr selector, IntPtr font, nfloat width, UILineBreakMode mode);
  • 11. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Expose Objectve-C to C# using Selectors • objc_msgSend functions Selectors NSString target = ... Selector selector = new Selector ("sizeWithFont:forWidth:lineBreakMode:"); UIFont font = ... nfloat width = ... UILineBreakMode mode = ... CGSize size = cgsize_objc_msgSend_IntPtr_float_int( target.Handle, selector.Handle, font == null ? IntPtr.Zero : font.Handle, width, mode);
  • 12. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Expose Managed Code to Objective-C Registrars [Register] class MyViewController : UIViewController{ [Export ("myFunc")] public void MyFunc () { } } C# (Managed Code) Objective-C @interface MyViewController : UIViewController { } -(void)myFunc; @end @implementation MyViewController {} -(void) myFunc { /* code to call the managed MyViewController.MyFunc method */ } @end
  • 13. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO XAMARIN IOS Single View Application
  • 14. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin.iOS creates a managed wrapper, called a peer object, for every native object accessed by the Xamarin.iOS runtime Peer wrapper objects UIKit.UIButton (peer object) [UIButton] (native object)IntPtrHandle Allocated by Xamarin.iOS and collected by the GC Allocated by the iOS runtime and reference counted
  • 15. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Peer object increment the retain count; it is released when the managed peer is disposed or finalized Memory allocation Xamarin.iOS 1 GC Collect [brelease] 0 b =null; b.Dispose(); [brelease] 0 var b = new UIButton(...) [[UIButton alloc]init] … or
  • 16. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Monitoring memory allocations Memory Analysis (Heap shot) Instrument s Androi d Device Monitor Xamarin Profiler VS Profiler
  • 17. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO MEMORY ALLOCATION Single View Application
  • 18. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Prefer full delegate methods over lambdas – it makes it easier to see and understand strong references Call Dispose() to release native resources immediately (vs. waiting ona GC) when you are finished with a peer wrapper Always unsubscribe from events you manually wire up; alternatively, use the Storyboard to connect events which can then be cleaned up automatically Xamarin.iOS Tips
  • 19. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Android native application
  • 20. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Android Native Compilation .dexfilesJava compile r Android dex compiler Java bytecodes Dalvik bytecodes
  • 21. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Android Native Compilation .dexfiles Resources (e.g. images) .apkfileAndroid apkbuilde r The .apkfile contains all the app's assets and is ready to run
  • 22. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Android Native Execution Bytecodes are compiled to native code at installation (called Ahead-of-Time or AOT) MyApp.apk Android Runtime (ART) Apps run in their own process with their own copy of the ART Virtual Machine
  • 23. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO ANDROID STUDIO
  • 24. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin.Android Architecture
  • 25. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin.Android Compilation assemblyC# compiler IL and metadata Linke r Monoassemblies yourassemblies Monoassemblies (filtered) Determines which class members are used in your app and includes only those members in the output yourassemblies (filtered)
  • 26. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin.Android Compilation Mono Runtime The Xamarin build tools add the Mono VM to your application package .apkfileAndroid apkbuilde r
  • 27. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO XAMARIN.ANDROID
  • 28. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin.Android GC Process GC Collect Can collect object? Is Peer Object ? Ye s Replace JNI handle with Weak Handle Ye s Force Android GC JNI handle collected ? Collect object No Ye s Replace JNI weak handle with strong handle reference NoPeer object kept alive
  • 29. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Integration between Xamarin GC and JVM GC is performed through a native extension called the GC Bridge GC Bridge Xamarin Manage d Memory Android Manage d Memory GC Bridge Process Memor y
  • 30. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • GC_ messages provide details about bridge and collection times Monitoring GC Performance GC_MAJOR:(Minor allowance) pause 29.11ms, total 29.35ms, bridge 0.15msmajor 4048K/0K los 2766K/0K Lower pause, bridge and total times are preferred
  • 31. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • C# objects must be boxed to create a JVM representation of the object; intrinsic types (strings, numeric values and dates) are all special cased Xamarin and the JAVA VM C# Object Java Object ArrayAdapter<Tweet> ArrayAdapter ArrayLi stTweet Tweet Tweet Tweet Tweet Tweet Tweet Tweet ListView
  • 32. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • Instead, do as much as possible in either C# or Java, interop is expensive Stay in your yard C# Object Java Object TweetAdapter List<Tweet> Tweet Tweet Tweet Tweet ListView
  • 33. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Should call Dispose() to release the native resources immediately (vs waiting on a GC) when you are finished with a peer wrapper Avoid placing a large numbers of references in peer objects, remember GC is more expensive for these special types Avoid passing pure C# custom types into Java APIs if possible Xamarin.Android Tips
  • 34. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Xamarin Process Memory UIView UIImage MKMapVie w ... Activity Intent TextView ... Managed Memory C# and .NET objects are allocated here - this is all GC knows about
  • 35. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Q & A

Notas do Editor

  1. Application Delegate is a protocol
  2. iOS Policy Cannot run dynamically generated code on a device
  3. Selector is a message that can be sent to an object or a class. Instance Selectors to Instance Methods and Class Selector to Static methods
  4. Selector is a message that can be sent to an object or a class. Instance Selectors to Instance Methods and Class Selector to Static methods
  5. Every managed class that derives from NSObject Added Objective-C member mirrored [Register] [Export]
  6. ART replaces Dalvik
  7. There is also JarSigner and optimizing the layout with zipalign
  8. Managed Callable Wrappers - JNI bridge. Android Callable Wrapper ACW for Activity1 constructor will invoke Actvity1 default constructor https://developer.xamarin.com/guides/android/under_the_hood/architecture/