import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String tag = "LifeCycleEvents";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag, "In the onCreate() event");
}
public void onStart()
{
super.onStart();
Log.d(tag, "In the onStart() event");
}
public void onRestart()
{
super.onRestart();
Log.d(tag, "In the onRestart() event");
}
public void onResume()
{
super.onResume();
Log.d(tag, "In the onResume() event");
}
public void onPause()
{
super.onPause();
Log.d(tag, "In the onPause() event");
}
public void onStop()
{
super.onStop();
Log.d(tag, "In the onStop() event");
}
public void onDestroy()
{
super.onDestroy();
Log.d(tag, "In the onDestroy() event");
}
}
Create - Activity is created.
Start - Current activity gets started.
Resume - Current activity has been in resumed state.
Restart - Current activity has been in restarted.
Pause - Current activity has been in Paused state.
Stop - Current activity has been in stopped state.
destroy - Current activity has been in destroyed state.
为什么有这么多类似的方法(onCreate(), onStart(),
onResume())在初始化期间调用,以及许多其他调用
(onPause(), onStop(), onDestroy())在结束时调用?< / p >