Beginning Android Programming For Beginners -- Chapter 6
The Life and Times of an Android App
Introduction to the Android Lifecycle
I've read several Android books in the past couple of years, and this is the first one that does a good job of explaining what the @override and the super.oncreate lines of code do.I don't think it matters that you understand, but I appreciate the author doesn't just let it all be "magic".
A simplified explanation of the Android Lifecycle
You can do a lot of things on a smartphone, and all of these things involve some part of the app life cycle. The author goes through a real life scenario that you might actually do.Lifecycle phases - Whate we need to know
There are 7 phases in the app lifecycle.- Being Created
- Starting
- Running
- Pausing
- Stopping
- Being Destroyed
Lifecycle Phases - What we need to do
While there is a lot of information in the lifecycle phases, we don't necessarily have to implement them all. There are various methods we will use when the lifecycle phases are used.- onCreate: When an app is started fresh
- onStart: After the onCreate is called, can also be called when an app is resumed
- onResume: Called when we come back to the app after we leave it for some reason
- onPause: Called when you get a phone call, or open another app
- onStop: Called before an app is likely to be destroyed
- onDestroy: Called when an app is about to be destroyed, either by the user of it can be destroyed by the Android operating system
The Lifecycle demonstration app
In this section, the author provides the code to build a very simple app that will allow you to test the Android lifecycle.The instructions to start a brand new app have changed since the book was written (and possibly since this blog post was written). There was no Blank Activity available, so I chose the Empty Activity (Shown Below)

We get some very basic, but clean code to allow us to investigate when all the various methods are called when you use an app, and when you leave the app. There are some very simple instructions to follow along with, and then explanations of what you saw when you followed those steps.
All in all this was a very good tutorial that will allow you to see when and where various parts of the code are called.
Comments
Post a Comment