Book Image

Learning Java by Building Android Games

By : John Horton
Book Image

Learning Java by Building Android Games

By: John Horton

Overview of this book

Table of Contents (17 chapters)
Learning Java by Building Android Games
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 2


Q1) What should you do if all this talk of life cycles, classes, and methods is a bit confusing?

A) Don't worry about them. Understanding comes a bit at a time, and if they are not entirely clear at this stage, it will not hold you back from thoroughly learning Java, and all will become clearer as we progress.

Q2) What exactly is a Java class?

A) Classes are a fundamental building block of Java programs. They are like containers for our Java code, and we can even use other people's classes to simplify the programs we write, even without seeing or understanding the code contained within those classes.

Q3) What is the difference between a method and a class?

A) Methods are contained within classes and represent the specific functionality of the class, like another container within a container. As an example from a game, we might have a Tank class with shoot, drive, and selfDestruct methods. We can use a class and its methods by making our own class, as we will in Chapter 6, OOP – Using Other People's Hard Work, or by using the @import statement as we did earlier in this chapter.

Q4) Take a look at the Android developer site and its more technical explanation of the lifecycle phases, at http://developer.android.com/reference/android/app/Activity.html. Can you see the phase and its related method that we haven't discussed? When would it be triggered in an app? What is the precise pathway an activity takes from creation to destruction?

A) It's the restarting phase. Its corresponding method is onRestart. It is triggered when an app has been stopped and then restarted. We won't need the onRestart method in this book, but this exercise hopefully helped clarify the concept of life cycles. The precise pathway will vary; we just need to handle the phases that are relevant to our game. So far, we have just tinkered with onCreate.