Professional Documents
Culture Documents
bryan costanich
em: bryanc@xamarin.com tw: @bryancostanich slides: slideshare.net/bryancostanich code: bit.ly/1avqivC
App Lifecycle + Patterns for Handling App Initialization Application Crashes and Restarts Asynchronous Initialization
Activity Lifecycle
Important Methods OnCreate ( ) - Initialize Stuf
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
Initialized Event
ActivityBase Check to see if App.Current.IsInitialized
Ap p public static App() protected - ctor () public static App Current public bool IsInitialized public event Initialized
Code Walkthrough 2
App Initialization
If activity re-launch fails, it moves backwards through the navigation history - Painful
Need to enable initialization on all activities
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
Code Walkthrough 5
Asynchronous Initialization