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

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 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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