Java Reference
In-Depth Information
Activity
subclasses override various
Activity
lifecycle callback methods
that
Android calls during the life of an activity. For example,
Listing 12-1
'
s
Sim-
pleActivity
class,whichisplacedinapackagebecauseAndroidmandatesthatan
app's components are to be stored in a unique package, extends
Activity
and also
overridesthe
void onCreate(Bundle bundle)
and
void onDestroy()
li-
fecycle callback methods.
Listing 12-1.
A skeletal activity
package ca.tutortutor.simpleapp;
import android.app.Activity;
import android.os.Bundle;
public class SimpleActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); // Always call
superclass method first.
System.out.println("oncreate(bundle) called");
}
@Override
public void onDestroy()
{
super.onDestroy(); // Always call superclass method
first.
System.out.println("ondestroy() called");
}
}
SimpleActivity
's overriding
onCreate(Bundle)
and
onDestroy()
methodsfirstinvoketheirsuperclasscounterparts,apatternthatmustbefollowedwhen
overriding the
void onStart()
,
void onRestart()
,
void onResume()
,
void onPause()
, and
void onStop()
lifecycle callback methods.