|
Written by Carl Whalley
|
|
Friday, 20 November 2009 09:00 |
|
Page 10 of 11
9. The App lifecycle
Never forget it's a phone!
Your app is entering into a pretty harsh environment - it can be subjected to all manner of external prods, kicks and pokes like running out of memory, running out of power or losing a signal. Oh, and a call might come in ;-) To support all this, the Android designers implemented a powerful lifecycle support mechanism, all aimed at preserving the integrity of your app no matter what manner of nasties it gets subjected to. Your app will receive callbacks, these are hooks in your code which you implement as methods with fixed names such as onPause() and onRestart(). This way, when these events occur, your code executes, giving you the chance to handle things in a controlled way, such as preserving data to storage when the app quits and so on.
Here's the Google diagram:

This is documented here. Seeing this for the first time might seem initimidating, but it's not really when you think of how the phone can be used. Say that call does come in - your app will be paused and sent to the background whilst the call is dealt with in the foreground. Your app's onPause() handler will be called. Then, after the call, the user may switch back to your app and so the onResume() method is invoked. Understanding the app lifecycle allows you to play nice with the rest of the handset and makes sure your users get no nasty surprises when using your app in their phone as a whole.
|
Comments
Android releases are named after desserts, so we had Cupcake (1.5), Donut (1.6) and Eclair (2.0), the next two are rumoured to be Flan and Gateaux
For graphics I'm a fan of Inkscape now. It's an awesome piece of software. Especially for doing games and similar stuff. All graphics of my own game Puzzle Blox have been created with Inkscape. Thumbs up!
RSS feed for comments to this post.