SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Cross-Platform Mobile
Development In C#
By Dan Hermes

Boston Mobile C# Developers' Group

dan@lexiconsystemsinc.com
www.lexiconsystemsinc.com
Going Native
iOS
 Android
 Windows

The Basics
UI
 Event life Cycles
 Multi-Threading
 Web Services
 Patterns

UI – Android


Xamarin Studio
◦ Xamarin Starter or Indie License



Visual Studio
◦ 2010+
◦ Professional+ (for plug-ins)
◦ Xamarin Business or Enterprise License



.axml
DEMO
UI - iOS
Xcode
 You need a Mac


◦ Mac Mini
◦ macincloud.com

DEMO
Xcode
Android: Activities
 An Activity

is like a…

◦ Windows Process
◦ ASP.NET Page Life Cycle
◦ MVC Page Life Cycle
Back vs. Home

Image courtesy of Xamarin

Back
•User is done with the Activity. Destroy it.

Home (or App Switcher)
•Suspend the Activity. Place in the background.
Activity States

Image courtesy of Xamarin
Activity Methods

Image courtesy of Xamarin
OnCreate – WHEN?
Creating views
 Initializing variables
 Binding static data to lists

Bundle – for Activity State
Key/value dictionary
 Bundle not null in OnCreate?
Restarting.

Activity Methods


OnStart - before an activity becomes visible
◦ refresh current values of views



OnResume - start interacting with the user
◦
◦
◦
◦
◦
◦



Ramping up frame rates
Starting animations
Listening for GPS updates
Display any relevant alerts or dialogs
Wire up external event handlers
Undo operations in OnPause

OnPause
◦
◦
◦
◦
◦

Commit changes to persistent data
Destroy or clean up other objects consuming resources
Ramp down frame rates and pausing animations
Unregister external event handlers or notification handlers
Clear dialogs and alerts
Activity Methods

Image courtesy of Xamarin
Activity Methods


OnStop - activity is no longer visible to the
user
◦ A new activity is being started and is covering
up this activity.
◦ An existing activity is being brought to the
foreground.
◦ The activity is being destroyed.



OnDestroy - final method
◦ Kill threads



OnRestart – prior to a restart
◦ Then OnStart – most reinit logic goes there
Managing State
 Bundle
◦ Primitive data types
 Custom Class
◦ Complex data (ex. Bitmap)

 Roll Your Own
◦ Circumvent the configuration change
lifecycle
iOS App Life Cycle

Image courtesy of Xamarin
iOS Lifecycle Methods

Image courtesy of Xamarin
iOS Lifecycle Methods


OnActivated

◦ upon launch or when app returns to foreground


OnResignActivation

◦ upon an interruption such as a text or phone call


DidEnterBackground

◦ user accepts the phone call
◦ save user data and tasks
◦ remove sensitive information from the screen


WillEnterForeground

◦ App returns to foreground from background or suspension
◦ Restore state saved during DidEnterBackground
◦ Then call OnActivated


WillTerminate

◦ App shuts down and process is destroyed
◦ If multitasking is not available on the device or the OS
version
◦ Memory is low
◦ User manually terminates a backgrounded application.
iOS vs. Android
App Life Cycle

Image courtesy of Xamarin
iOS:Events, Protocols, and
Delegates


Events

◦ Xamarin.iOS exposes .NET events on
UIKit controls
 Protocols
◦ Like a C# interface with optional methods
◦ Xamarin.iOS implements using abstract classes


Delegates
◦ strongly and weakly typed
◦ not be confused with C# delegates
Performance
Mobile users expect it
 Delays are annoying and alienate
users
 Android Activities and iOS Delegates?


◦ run in the foreground UI Thread


Long-running code should go into a…
Background Thread
Good Candidates for a
Background Thread


Operations that
◦ Make requests off of the device
 Retrieve data (web service, RSS feed)
 Connect to network
 Downloads

◦ Run more than 50 milliseconds
◦ May block the user interface thread
 Watchdog thread to kill the app
Async/Await
async
◦ method declaration
◦ lambda
◦ anonymous method
 await
◦ code stops and waits
◦ spawns background thread
◦ UI thread is not blocked
◦ resumes at the same point in the code

Async/Await
Async/Await
GetStringAsync
 PutAsync
 PostAsync
 DeleteAsync

Async Support


Xamarin.iOS
◦ 174 methods



Xamarin.Android
◦ 337 methods

Xamarin.Mobile
 Xamarin Component Store

Web Services
REST
 WCF
 SOAP

REST







HttpWebRequest / WebClient
RestSharp
Hammock
NSURLConnection
ServiceStack
Web Patterns
Async/Await
 MVC
 MVVMCross

MVC


Model
◦ Can use them



Views
◦ Must use them



Controllers
◦ Android Activities
◦ iOS AppDelegates
Cross-Platform Mobile
Development In C#
Dan Hermes
Mobile Consultant
Lexicon Systems

Are You Mobilizing?
Website: www.lexiconsystemsinc.com
Email: dan@lexiconsystemsinc.com
Phone: 781-526-0738
Twitter: @lexiconsystems
Blog: www.itshopkeeping.com

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (6)

Pieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React NativePieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React Native
 
Introduction to React Native & Redux
Introduction to React Native & ReduxIntroduction to React Native & Redux
Introduction to React Native & Redux
 
Core Image Tips & Tricks in iOS 9
Core Image Tips & Tricks in iOS 9Core Image Tips & Tricks in iOS 9
Core Image Tips & Tricks in iOS 9
 
Integrating Mobile Technology in the Construction Industry
Integrating Mobile Technology in the Construction IndustryIntegrating Mobile Technology in the Construction Industry
Integrating Mobile Technology in the Construction Industry
 
하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React Native
 

Ähnlich wie Cross platform mobile development in c#

Ähnlich wie Cross platform mobile development in c# (20)

Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
 
Developing advanced universal apps using html & js
Developing advanced universal apps using html & jsDeveloping advanced universal apps using html & js
Developing advanced universal apps using html & js
 
Gradle for Android Developers
Gradle for Android DevelopersGradle for Android Developers
Gradle for Android Developers
 
Optimizing Apps for Better Performance
Optimizing Apps for Better PerformanceOptimizing Apps for Better Performance
Optimizing Apps for Better Performance
 
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
 
An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)
 
Mobile application and Game development
Mobile application and Game developmentMobile application and Game development
Mobile application and Game development
 
Connecting your apps to the cloud: Mobile CMS
Connecting your apps to the cloud: Mobile CMSConnecting your apps to the cloud: Mobile CMS
Connecting your apps to the cloud: Mobile CMS
 
Build 2017 - B8099 - What's new in Xamarin.Forms
Build 2017 - B8099 - What's new in Xamarin.FormsBuild 2017 - B8099 - What's new in Xamarin.Forms
Build 2017 - B8099 - What's new in Xamarin.Forms
 
The web - What it has, what it lacks and where it must go - keynote at Riga D...
The web - What it has, what it lacks and where it must go - keynote at Riga D...The web - What it has, what it lacks and where it must go - keynote at Riga D...
The web - What it has, what it lacks and where it must go - keynote at Riga D...
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
Case study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionCase study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversion
 
Xamarin.iOS introduction
Xamarin.iOS introductionXamarin.iOS introduction
Xamarin.iOS introduction
 
Progressive Web Apps 101
Progressive Web Apps 101Progressive Web Apps 101
Progressive Web Apps 101
 
iOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections TalkiOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections Talk
 
Introduction to Android Programming
Introduction to Android ProgrammingIntroduction to Android Programming
Introduction to Android Programming
 
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
 

Mehr von danhermes

What can mobile do for me
What can mobile do for meWhat can mobile do for me
What can mobile do for me
danhermes
 
Mastering human communication patterns
Mastering human communication patternsMastering human communication patterns
Mastering human communication patterns
danhermes
 

Mehr von danhermes (9)

Azure Mobile Apps with Xamarin
Azure Mobile Apps with XamarinAzure Mobile Apps with Xamarin
Azure Mobile Apps with Xamarin
 
Developing Cross-platform Native Apps with Xamarin
Developing Cross-platform Native Apps with XamarinDeveloping Cross-platform Native Apps with Xamarin
Developing Cross-platform Native Apps with Xamarin
 
Xamarin Navigation Patterns
Xamarin Navigation PatternsXamarin Navigation Patterns
Xamarin Navigation Patterns
 
Building Mobile Apps for Business
Building Mobile Apps for BusinessBuilding Mobile Apps for Business
Building Mobile Apps for Business
 
Mobile UI Design Patterns
Mobile UI Design PatternsMobile UI Design Patterns
Mobile UI Design Patterns
 
How App Usability, Functionality, and Analysis are Changing with Mobile
  How App Usability, Functionality, and Analysis are Changing with Mobile  How App Usability, Functionality, and Analysis are Changing with Mobile
How App Usability, Functionality, and Analysis are Changing with Mobile
 
What can mobile do for me
What can mobile do for meWhat can mobile do for me
What can mobile do for me
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
 
Mastering human communication patterns
Mastering human communication patternsMastering human communication patterns
Mastering human communication patterns
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Cross platform mobile development in c#

Hinweis der Redaktion

  1. What about App select button?
  2. Partial or transparent Activity? HOW TO PAUSE????
  3. Restart should go to OnCreate()?? (so bundle can reload)
  4. Caution: Your activity will be destroyed and recreated each time the user rotates the screen. When the screen changes orientation, the system destroys and recreates the foreground activity because the screen configuration has changed and your activity might need to load alternative resources (such as the layout).
  5. Restart should go to OnCreate()?? (so bundle can reload)
  6. http://docs.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_1_introduction_to_backgrounding_in_ios/Not Running - The application has not yet been launched on the device.Running/Active - The application is on the screen, and is executing code in the foreground.Inactive - The application is interrupted by an incoming phone call, text, or other interruption.Backgrounded - The application moves into the background and continues executing background code.Suspended - If the application does not have any code to run in the background, or if all code has completed, the app will be Suspended by the OS. A suspended application's process is kept alive, but the application is unable to execute any code in this state.Return to Not Running/Termination (Rare) - Occasionally, the application's process is destroyed, and the application returns to the Not Running state. This happens in low-memory situations, or if the user manually terminates the application.
  7. OnActivated - This is called the first time the application is launched, and every time the app comes back into the foreground. This is the place to put code that needs to run every time the app is opened.OnResignActivation - If the user receives an interruption such as a text or phone call, this method gets called and the app is temporarily inactivated. Should the user accept the phone call, the app will be sent to the background.DidEnterBackground - Called when the app enters the backgrounded state, this method gives an application about five seconds to prepare for possible termination. Use this time to save user data and tasks, and remove sensitive information from the screen.WillEnterForeground - When a user returns to a backgrounded or suspended application, and launches it into the foreground, WillEnterForeground gets called. This is the time to prepare the app to take the foreground by rehydrating any state saved during DidEnterBackground. OnActivated will be called immediately after this method completes.WillTerminate - The application is shut down, and its process is destroyed. This method only gets called if multitasking is not available on the device or the OS version, if memory is low, or if the user manually terminates a backgrounded application. Note that suspended applications that get terminated will not callWillTerminate.
  8. OnActivated - This is called the first time the application is launched, and every time the app comes back into the foreground. This is the place to put code that needs to run every time the app is opened.OnResignActivation - If the user receives an interruption such as a text or phone call, this method gets called and the app is temporarily inactivated. Should the user accept the phone call, the app will be sent to the background.DidEnterBackground - Called when the app enters the backgrounded state, this method gives an application about five seconds to prepare for possible termination. Use this time to save user data and tasks, and remove sensitive information from the screen.WillEnterForeground - When a user returns to a backgrounded or suspended application, and launches it into the foreground, WillEnterForeground gets called. This is the time to prepare the app to take the foreground by rehydrating any state saved during DidEnterBackground. OnActivated will be called immediately after this method completes.WillTerminate - The application is shut down, and its process is destroyed. This method only gets called if multitasking is not available on the device or the OS version, if memory is low, or if the user manually terminates a backgrounded application. Note that suspended applications that get terminated will not callWillTerminate.
  9. http://docs.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_1_introduction_to_backgrounding_in_ios/Not Running - The application has not yet been launched on the device.Running/Active - The application is on the screen, and is executing code in the foreground.Inactive - The application is interrupted by an incoming phone call, text, or other interruption.Backgrounded - The application moves into the background and continues executing background code.Suspended - If the application does not have any code to run in the background, or if all code has completed, the app will be Suspended by the OS. A suspended application's process is kept alive, but the application is unable to execute any code in this state.Return to Not Running/Termination (Rare) - Occasionally, the application's process is destroyed, and the application returns to the Not Running state. This happens in low-memory situations, or if the user manually terminates the application.
  10. Android Activities and iOS Delegates?run in the foreground UI ThreadMobile devices refresh their screen at 60 frames per second. A screen refresh will take place every 16.7 milliseconds. Movies are typically shown at a rate of 24 or 25 frames per second. This data indicates that the human eye can detect changes starting at around 20 frames per second. Anything that delays an update can cause a delay that is perceptible to the human eyea watchdog built into a device will kill the application that is blocking the UI thread.
  11. Uses the Task Parallel Library(TPL) ???Need code exampleThe recommended approach?await operator can be applied to a Task inside a method marked as async. It causes the method to stop execution at that point and wait until the task completes.
  12. Uses the Task Parallel Library(TPL) ???Need code exampleThe recommended approach?await operator can be applied to a Task inside a method marked as async. It causes the method to stop execution at that point and wait until the task completes.
  13. One of the new features of .NET 4.5/Mono 3.2 is the inclusion of the System.Net.Http.HttpClient class. This class is designed to perform asynchronous requests via the GET, POST, PUT, & DELETE Http verbs. The method calls for this are: There are other methods that this class exposes. Some of these methods are: CancelPendingRequests GetByteArrayAsync GetStreamAsync SendAsync