package com.asfman;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AndroidLifeCycle extends Activity {
public void onCreate(Bundle savedInstanceState) {
Log.i("info", "First Activity =======onCreate()========");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(AndroidLifeCycle.this, Second.class);
startActivity(intent);
//AndroidLifeCycle.this.finish(); //trigger onDestroy
}
});
}
// Called after onCreate — or after onRestart when the activity had been
// stopped, but is now again being displayed to the user. It will be
// followed by onResume
protected void onStart() {
Log.i("info", "First Activity =======onStart()========");
super.onStart();
}
// Called after onRestoreInstanceState, onRestart, or onPause, for your
// activity to start interacting with the user
protected void onResume() {
Log.i("info", "First Activity =======onResume()========");
super.onResume();
}
// Called as part of the activity lifecycle when an activity is going into
// the background, but has not (yet) been killed
protected void onPause() {
Log.i("info", "First Activity =======onPause()========");
super.onPause();
}
// Called when you are no longer visible to the user. You will next receive
// either onRestart, onDestroy, or nothing, depending on later user
// activity.
protected void onStop() {
Log.i("info", "First Activity =======onStop()========");
super.onStop();
}
// Perform any final cleanup before an activity is destroyed
protected void onDestroy() {
Log.i("info", "First Activity =======onDestroy()========");
super.onDestroy();
}
// Called after onStop when the current activity is being re-displayed to
// the user (the user has navigated back to it). It will be followed by
// onStart and then onResume
protected void onRestart() {
Log.i("info", "First Activity =======onRestart()========");
super.onRestart();
}
}
package com.asfman;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Second extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Log.i("info", "Second Activity =======onCreate()========");
}
// Called after onCreate — or after onRestart when the activity had been
// stopped, but is now again being displayed to the user. It will be
// followed by onResume
protected void onStart() {
Log.i("info", "Second Activity =======onStart()========");
super.onStart();
}
// Called after onRestoreInstanceState, onRestart, or onPause, for your
// activity to start interacting with the user
protected void onResume() {
Log.i("info", "Second Activity =======onResume()========");
super.onResume();
}
// Called as part of the activity lifecycle when an activity is going into
// the background, but has not (yet) been killed
protected void onPause() {
Log.i("info", "Second Activity =======onPause()========");
super.onPause();
}
// Called when you are no longer visible to the user. You will next receive
// either onRestart, onDestroy, or nothing, depending on later user
// activity.
protected void onStop() {
Log.i("info", "Second Activity =======onStop()========");
super.onStop();
}
// Perform any final cleanup before an activity is destroyed
protected void onDestroy() {
Log.i("info", "Second Activity =======onDestroy()========");
super.onDestroy();
}
// Called after onStop when the current activity is being re-displayed to
// the user (the user has navigated back to it). It will be followed by
// onStart and then onResume
protected void onRestart() {
Log.i("info", "Second Activity =======onRestart()========");
super.onRestart();
}
}
Active/Runing一个新 Activity 启动入栈后,它在屏幕最前端,处于栈的最顶端,此时它处于可见并可和用户交互的激活状态.
Paused 当 Activity 被另一个透明或者 Dialog 样式的 Activity 覆盖时的状态.此时它依然与窗口管理器保持连接,系统继续维护其内部状态,所以它仍然可见,但它已经失去了焦点故不可与用户交互.
Stoped 当 Activity 被另外一个 Activity 覆盖、失去焦点并不可见时处于 Stoped状态.
Killed Activity 被系统杀死回收或者没有被启动时处于 Killed状态.
posted on 2011-03-31 17:40
汪杰 阅读(527)
评论(3) 编辑 收藏 引用 所属分类:
Java