Now that we have our UI designed in XML, we are ready to switch over to Java. Remember from earlier in this chapter that Android provides two ways for building user interfaces. One is by declaring it in XML, which is what we just did, and we got as far as we could (for now). The other one is to build it programmatically in Java. We also said earlier that the best practice is to get as far as possible in XML and then switch over to Java.
Our Java class for this is
and the Eclipse New Project dialog has already created the stub for this
class. The class is part of the
com.marakana.yamba1 Java package, and as such
is part of that directory.
As with all main building blocks in Android, such as
activities, services, broadcast receivers, and content providers, you
usually start by subclassing a base class provided by the Android
framework and overriding certain inherited methods. In this case, we
and override its
onCreate() method. As
you recall, activities have a certain life cycle (see Activity Life Cycle), or state machine through which they
go. We as developers do not control what state the activity is in, but
we do get to say what happens during a transition to a particular
state. In this case, the transition we want to override is the
onCreate() method that the system’s
ActivityManager invokes when the activity is first created (i.e., ...