Android Programming for Beginners
上QQ阅读APP看书,第一时间看更新

A simplified explanation of the Android lifecycle

If you have ever used an Android device, you have probably noticed it works quite differently than many other operating systems. For example, you can be using an app, say you're checking what people are doing on Facebook. Then you get an e-mail notification and you tap the e-mail icon to read it. Mid-way through reading the e-mail you might get a Twitter notification, and because you're waiting on important news from someone you follow, you interrupt your e-mail reading and change apps to Twitter, with one touch.

After reading the tweet, you fancy a game of Angry Birds, but mid-way through the first daring fling you suddenly remember that Facebook post. So you quit Angry Birds and tap the Facebook icon.

Then you resume Facebook, probably at the same point you left it. You could have resumed reading the e-mail, decided to reply to the tweet, or started an entirely new app.

All this backwards and forwards takes quite a lot of management on the part of the operating system, apparently independent from the individual apps themselves.

The difference between, say, a Windows PC and Android in the context we have just discussed is this: with Android, although the user decides which app they are using, the OS decides if and when to actually close down (destroy) an application, and our user's data (like the hypothetical note) along with it. We just need to consider this when coding our apps.