But, hey! Why I should care about the life cycle? That's a very good point! There are a lot of things that you should, or must, do while your application is switching from one state to another.
Here are some examples:
- Handle the current input control's state. You can save or discard data, but you cannot send the Do you want to save? message to the user. If a user touches the Home button, you cannot stop them. For this specific situation, it could be useful to have the OnSaveState form event too, which is an abstraction of what we are talking about.
- Stop or restart CPU intensive work related to a calculation.
- Look for some previously saved data on the file system.
- Search Bluetooth devices or app tethering-enabled applications.
- Update a remote resource more frequently than when the app was running in the background. In the background, you may check a particular HTTP resource once an hour, while if the app is in the foreground, you can decide whether to check that resource once a minute.
- Append a system notification to remind the user of something just before terminating an app.
- Stop the audio output (if applicable for your app).
- Stop the GPS monitoring (if applicable for your app).
- Go into power saving mode, whatever it means for your app, and many more.
As you can see, the application's life cycle is very important. Let's see how we can hook up to it.