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.

Some other overridden methods

This section quickly mentions the menuInflator code we have seen earlier in the book.  I didn't actually see this in my app.  This might be from an older version of Android Studio.  Still it's good information to know.

The structure of Java code - revisited

We are introduced to the concept of classes and extending them in Java.  Again, I am very impressed with how the author has actually written a book that explains things that may not be obvious to all people, especially in a book for beginners.  Too many computer writers leave too many things as "magic".  They don't take the time to explain concepts that the average new programmer won't know.  I like to know we do things the way we are doing them.

Comments

Popular posts from this blog

Go Programming Blueprints, Chapter 2, Adding User Accounts

Successful Big Game Hunting Chapter 10