SlideShare a Scribd company logo
1 of 15
Android

App Lifecycle +
Advanced
Architectures/Patterns/Problems
bryan costanich

em: bryanc@xamarin.com
tw: @bryancostanich
slides: slideshare.net/bryancostanich
code: bit.ly/1avqivC
What We'll Cover
• Review Activity Lifecycle
• Relation to the App
Lifecycle

• App Lifecycle + Patterns
for Handling
• App Initialization

• Review States +
Important Events

• Application Crashes and
Restarts

• Background Updates

• Asynchronous
Initialization

• Configuration Changes
Activity Lifecycle
Important Methods
OnCreate ( ) - Initialize Stuf
OnResume ( ) - Begin Life
OnPause ( ) - Stop/Pause
Code Walkthrough 1
Activity Lifecycle
App Initialization
Common to need to initialize things at the beginning of the App
Lifecycle
Sometimes these can take a while
Common approach is to show a loading screen
Pattern: App
Singleton
App Singleton Class
bool IsInitialized Property
Initialized Event
ActivityBase
Check to see if
App.Current.IsInitialized

App
public static
App()
protected - ctor
()
public static App
Current
public bool
IsInitialized
public event
Initialized
Code Walkthrough 2
App Initialization
App Initialization After Crash
• Unhandled Exceptions will cause Android to kill the process
• AppDomain and all objects in it will be cleaned up by Mono
• Android will still attempt to launch last running activity
• If it relies on initialization, activity won’t make sense
• If activity re-launch fails, it moves backwards through the
navigation history - Painful
• Need to enable initialization on all activities
• Sometimes want to force load of launch activity
Code Walkthrough 3
App Initialization, Post-Crash
Unhandled Exceptions
• In other app platforms, can be handled at an App level
• AppDomain.CurrentDomain.UnhandledException +=
HandleUnhandledException;
• Trickier in Android - Will cause a “Spectacular Crash”
• Some day, this story will be better, can at least log now
• See in Android Log
protected void HandleUnhandledException (object sender,
UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine ("Unhandled Exception = " + e.Message);
}

Code Walkthrough 4
Waiting for Async Initializations
• Sometimes app needs to wait for multiple
asynchronous inits
• e.g.: binding to more than one service
• or service + web request
• etc.
• Same pattern as before, but keep track of inits
• When all inits complete, raise Initialized event
Code Walkthrough 5
Asynchronous Initialization
Q+A

More Related Content

What's hot

How Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationHow Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationShaun McDonald
 
The what, why and how of web analytics testing
The what, why and how of web analytics testingThe what, why and how of web analytics testing
The what, why and how of web analytics testingAnand Bagmar
 
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013Wooga
 
TiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium appsTiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium appsTim Poulsen
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practicesAlessio Ricco
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineKeir Bowden
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsYakov Fain
 
Challenges in writing roboelectric tests
Challenges in writing roboelectric tests Challenges in writing roboelectric tests
Challenges in writing roboelectric tests BlrDroid
 

What's hot (12)

Ug. marketplace testing
Ug. marketplace testingUg. marketplace testing
Ug. marketplace testing
 
Understanding meteor
Understanding meteorUnderstanding meteor
Understanding meteor
 
How Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationHow Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 Migration
 
Activity
ActivityActivity
Activity
 
The what, why and how of web analytics testing
The what, why and how of web analytics testingThe what, why and how of web analytics testing
The what, why and how of web analytics testing
 
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
 
TiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium appsTiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium apps
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
WordCamp Bucharest 2017
WordCamp Bucharest 2017WordCamp Bucharest 2017
WordCamp Bucharest 2017
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with Jasmine
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
Challenges in writing roboelectric tests
Challenges in writing roboelectric tests Challenges in writing roboelectric tests
Challenges in writing roboelectric tests
 

Similar to Advanced android app lifecycle + Patterns

Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile AppsCraig Dunn
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsKazuaki Matsuo
 
Tizen application inside out
Tizen application inside outTizen application inside out
Tizen application inside outEun Young Lee
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
MDAD 4 - Android - Basics of UI Applications
MDAD 4 - Android - Basics of UI ApplicationsMDAD 4 - Android - Basics of UI Applications
MDAD 4 - Android - Basics of UI ApplicationsAlexandru Radovici
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxNgLQun
 
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptxSlide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptxraditya gumay
 
Automated Exploratory Testing
Automated Exploratory TestingAutomated Exploratory Testing
Automated Exploratory TestingJustin Ison
 
A look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingA look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingMatt Lacey
 
Cross-platform logging and analytics
Cross-platform logging and analyticsCross-platform logging and analytics
Cross-platform logging and analyticsDrew Crawford
 
Justin Ison
Justin IsonJustin Ison
Justin IsonCodeFest
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016jtmelton
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Droidcon Eastern Europe
 

Similar to Advanced android app lifecycle + Patterns (20)

Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile Apps
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applications
 
Tizen application inside out
Tizen application inside outTizen application inside out
Tizen application inside out
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
crashing in style
crashing in stylecrashing in style
crashing in style
 
MDAD 4 - Android - Basics of UI Applications
MDAD 4 - Android - Basics of UI ApplicationsMDAD 4 - Android - Basics of UI Applications
MDAD 4 - Android - Basics of UI Applications
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptxSlide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
 
Automated Exploratory Testing
Automated Exploratory TestingAutomated Exploratory Testing
Automated Exploratory Testing
 
A look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingA look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processing
 
Cross-platform logging and analytics
Cross-platform logging and analyticsCross-platform logging and analytics
Cross-platform logging and analytics
 
Justin Ison
Justin IsonJustin Ison
Justin Ison
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
 

More from bryan costanich

Hardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarinHardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarinbryan costanich
 
Teardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarinTeardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarinbryan costanich
 
Hacking your coffee maker; building a connected appliance with Netduino and X...
Hacking your coffee maker; building a connected appliance with Netduino and X...Hacking your coffee maker; building a connected appliance with Netduino and X...
Hacking your coffee maker; building a connected appliance with Netduino and X...bryan costanich
 
Cross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with XamarinCross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with Xamarinbryan costanich
 
Going mobile - A Technical Job Prep for Vassar Students
Going mobile - A Technical Job Prep for Vassar StudentsGoing mobile - A Technical Job Prep for Vassar Students
Going mobile - A Technical Job Prep for Vassar Studentsbryan costanich
 
Cross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual StudioCross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual Studiobryan costanich
 
Cross Platform Development with Xamarin
Cross Platform Development with XamarinCross Platform Development with Xamarin
Cross Platform Development with Xamarinbryan costanich
 

More from bryan costanich (9)

Hardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarinHardware hackers - hacking appliances with netduino + xamarin
Hardware hackers - hacking appliances with netduino + xamarin
 
Teardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarinTeardown Conference: hacking appliances with netduino + xamarin
Teardown Conference: hacking appliances with netduino + xamarin
 
Hacking your coffee maker; building a connected appliance with Netduino and X...
Hacking your coffee maker; building a connected appliance with Netduino and X...Hacking your coffee maker; building a connected appliance with Netduino and X...
Hacking your coffee maker; building a connected appliance with Netduino and X...
 
Futures in Computing
Futures in Computing Futures in Computing
Futures in Computing
 
C# rocks
C# rocksC# rocks
C# rocks
 
Cross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with XamarinCross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with Xamarin
 
Going mobile - A Technical Job Prep for Vassar Students
Going mobile - A Technical Job Prep for Vassar StudentsGoing mobile - A Technical Job Prep for Vassar Students
Going mobile - A Technical Job Prep for Vassar Students
 
Cross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual StudioCross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual Studio
 
Cross Platform Development with Xamarin
Cross Platform Development with XamarinCross Platform Development with Xamarin
Cross Platform Development with Xamarin
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Advanced android app lifecycle + Patterns

  • 2. bryan costanich em: bryanc@xamarin.com tw: @bryancostanich slides: slideshare.net/bryancostanich code: bit.ly/1avqivC
  • 3. What We'll Cover • Review Activity Lifecycle • Relation to the App Lifecycle • App Lifecycle + Patterns for Handling • App Initialization • Review States + Important Events • Application Crashes and Restarts • Background Updates • Asynchronous Initialization • Configuration Changes
  • 4. Activity Lifecycle Important Methods OnCreate ( ) - Initialize Stuf OnResume ( ) - Begin Life OnPause ( ) - Stop/Pause
  • 6. App Initialization Common to need to initialize things at the beginning of the App Lifecycle Sometimes these can take a while Common approach is to show a loading screen
  • 7. Pattern: App Singleton App Singleton Class bool IsInitialized Property Initialized Event ActivityBase Check to see if App.Current.IsInitialized App public static App() protected - ctor () public static App Current public bool IsInitialized public event Initialized
  • 8. Code Walkthrough 2 App Initialization
  • 9. App Initialization After Crash • Unhandled Exceptions will cause Android to kill the process • AppDomain and all objects in it will be cleaned up by Mono • Android will still attempt to launch last running activity • If it relies on initialization, activity won’t make sense • If activity re-launch fails, it moves backwards through the navigation history - Painful • Need to enable initialization on all activities • Sometimes want to force load of launch activity
  • 10. Code Walkthrough 3 App Initialization, Post-Crash
  • 11. Unhandled Exceptions • In other app platforms, can be handled at an App level • AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException; • Trickier in Android - Will cause a “Spectacular Crash” • Some day, this story will be better, can at least log now • See in Android Log
  • 12. protected void HandleUnhandledException (object sender, UnhandledExceptionEventArgs args) { Exception e = (Exception) args.ExceptionObject; Console.WriteLine ("Unhandled Exception = " + e.Message); } Code Walkthrough 4
  • 13. Waiting for Async Initializations • Sometimes app needs to wait for multiple asynchronous inits • e.g.: binding to more than one service • or service + web request • etc. • Same pattern as before, but keep track of inits • When all inits complete, raise Initialized event
  • 15. Q+A

Editor's Notes

  1. C# or Java. Same problems.
  2. the most important methods to override and implement are OnCreate(), OnResume(), and OnPause(). > OnCreate() - Load/inflate your UI, instantiate any controls, get references to controls in your view, wire up any local event handlers > OnResume() - Rehydrate UI state, Wire up any external event/notification handlers, start updating UI, basically, undo ANYTHING that you do in OnPause() > OnPause() - Remove any external event handlers, dismiss any dialogs, pause UI updates. Why? because if the Activity is paused and then reactivated, OnResume will be the only next method. OnCreate will be called when the Activity is first Instanced, but OnResume is the only method guaranteed to be called when an activity is activated.
  3. Cover: > app.cs - we’re using this to provide an external update to subscribe to MainActivity.cs > OnCreate > OnResume > OnPause > AddHandlers > RemoveHandlers
  4. Cover: App.cs > Initialized Event > IsInitialized property > .ctor: now takes a little while, also that it’s in a Task() because it is blocking (started from a UI thread)
  5. Examine: App.cs > wire up the AppDomain.CurrentDomain.UnhandledException handler
  6. If you have a single asynchronous initialization, it’s easy to handle. If you’re using the pattern we’ve been examining, you simply raise the App.Initialized event in the completion handler. However, sometimes you need to initialize multiple asynchronous things. For example, if you’re binding to more than one service, or you’re binding to a service and also waiting for a web request to finish, etc. Handling this scenario is actually quite simple. We use the same pattern as before, but we extend it but keeping track of the number things that require initialization, and when we hit the threshold, that is, when all the initializations complete, we raise the Initialized event and we’re on our way.
  7. Examine: App.cs > totalInitCount > currentInitCount > IncrementInitCount > .ctor - service connected calls IncrementInitCount Also Service Binding Generics