//打印应用程序的生命周期中执行的函数次序. 注:昨天的服务播放音乐,在公司把avd2.1模拟器删除重建后,可以听音乐.也一并删除了所有原安装的测试程序,不用一个一个删除了.
//刚进入程序时运行的函数
11-07 02:35:53.526: V/Gf_cycleActivity(401): onCreate
11-07 02:35:53.526: V/Gf_cycleActivity(401): onStart
11-07 02:35:53.526: V/Gf_cycleActivity(401): onResume
11-07 02:36:04.196: V/Gf_cycleActivity(401): onPause
//跳转到Gf_cycleActivity2程序时运行的函数
11-07 02:36:04.216: V/Gf_cycleActivity2(401): onCreate
11-07 02:36:04.216: V/Gf_cycleActivity2(401): onStart
11-07 02:36:04.216: V/Gf_cycleActivity2(401): onResume
11-07 02:36:04.336: V/Gf_cycleActivity(401): onStop
11-07 02:36:04.336: V/Gf_cycleActivity(401): onDestroy
//从Gf_cycleActivity2跳回到Gf_cycleActivity1程序时运行的函数
11-07 02:36:08.347: V/Gf_cycleActivity2(401): onPause
11-07 02:36:08.366: V/Gf_cycleActivity(401): onCreate
11-07 02:36:08.366: V/Gf_cycleActivity(401): onStart
11-07 02:36:08.366: V/Gf_cycleActivity(401): onResume
11-07 02:36:08.768: V/Gf_cycleActivity2(401): onStop
11-07 02:36:08.768: V/Gf_cycleActivity2(401): onDestroy
//Gf_cycleActivity1程序退出时运行的函数
11-07 02:36:10.548: V/Gf_cycleActivity(401): onPause
11-07 02:36:11.052: V/Gf_cycleActivity(401): onStop
11-07 02:36:11.052: V/Gf_cycleActivity(401): onDestroy
Activity01.java
package com.cycle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class Activity01 extends Activity
{
private static final String TAG = "Activity01";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.v(TAG, "onCreate");
Button button1 = (Button) findViewById(R.id.button1);
/* 监听button的事件信息 */
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 新建一个Intent对象 */
Intent intent = new Intent();
/* 指定intent要启动的类 */
intent.setClass(Activity01.this, Activity02.class);
/* 启动一个新的Activity */
startActivity(intent);
/* 关闭当前的Activity */
Activity01.this.finish();
}
});
/******************************/
Button button3 = (Button) findViewById(R.id.button3);
/* 监听button的事件信息 */
button3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 关闭当前的Activity */
Activity01.this.finish();
}
});
}
public void onStart()
{
super.onStart();
Log.v(TAG, "onStart");
}
public void onResume()
{
super.onResume();
Log.v(TAG, "onResume");
}
public void onPause()
{
super.onPause();
Log.v(TAG, "onPause");
}
public void onStop()
{
super.onStop();
Log.v(TAG, "onStop");
}
public void onDestroy()
{
super.onDestroy();
Log.v(TAG, "onDestroy");
}
public void onRestart()
{
super.onRestart();
Log.v(TAG, "onReStart");
}
}
Activity02.java
package com.cycle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class Activity02 extends Activity
{
private static final String TAG = "Activity02";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Log.v(TAG, "onCreate");
Button button = (Button) findViewById(R.id.button2);
/* 监听button的事件信息 */
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 新建一个Intent对象 */
Intent intent = new Intent();
/* 指定intent要启动的类 */
intent.setClass(Activity02.this, Activity01.class);
/* 启动一个新的Activity */
startActivity(intent);
/* 关闭当前的Activity */
Activity02.this.finish();
}
});
}
public void onStart()
{
super.onStart();
Log.v(TAG, "onStart");
}
public void onResume()
{
super.onResume();
Log.v(TAG, "onResume");
}
public void onPause()
{
super.onPause();
Log.v(TAG, "onPause");
}
public void onStop()
{
super.onStop();
Log.v(TAG, "onStop");
}
public void onDestroy()
{
super.onDestroy();
Log.v(TAG, "onDestroy");
}
public void onRestart()
{
super.onRestart();
Log.v(TAG, "onReStart");
}
}
Gf_cycleActivity.java
package packagename.Gfcycle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class Gf_cycleActivity extends Activity
{
private static final String TAG = "Gf_cycleActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.v(TAG, "onCreate");
Button button1 = (Button) findViewById(R.id.button1);
/* 监听button的事件信息 */
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 新建一个Intent对象 */
Intent intent = new Intent();
/* 指定intent要启动的类 */
intent.setClass(Gf_cycleActivity.this, Gf_cycleActivity2.class);
/* 启动一个新的Activity */
startActivity(intent);
/* 关闭当前的Activity */
Gf_cycleActivity.this.finish();
}
});
/******************************/
Button button3 = (Button) findViewById(R.id.button3);
/* 监听button的事件信息 */
button3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 关闭当前的Activity */
Gf_cycleActivity.this.finish();
}
});
}
public void onStart()
{
super.onStart();
Log.v(TAG, "onStart");
}
public void onResume()
{
super.onResume();
Log.v(TAG, "onResume");
}
public void onPause()
{
super.onPause();
Log.v(TAG, "onPause");
}
public void onStop()
{
super.onStop();
Log.v(TAG, "onStop");
}
public void onDestroy()
{
super.onDestroy();
Log.v(TAG, "onDestroy");
}
public void onRestart()
{
super.onRestart();
Log.v(TAG, "onReStart");
}
}
Gf_cycleActivity2.java
package packagename.Gfcycle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class Gf_cycleActivity2 extends Activity
{
private static final String TAG = "Gf_cycleActivity2";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Log.v(TAG, "onCreate");
Button button1 = (Button) findViewById(R.id.button2);
/* 监听button的事件信息 */
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
/* 新建一个Intent对象 */
Intent intent = new Intent();
/* 指定intent要启动的类 */
intent.setClass(Gf_cycleActivity2.this, Gf_cycleActivity.class);
/* 启动一个新的Activity */
startActivity(intent);
/* 关闭当前的Activity */
Gf_cycleActivity2.this.finish();
}
});
}
public void onStart()
{
super.onStart();
Log.v(TAG, "onStart");
}
public void onResume()
{
super.onResume();
Log.v(TAG, "onResume");
}
public void onPause()
{
super.onPause();
Log.v(TAG, "onPause");
}
public void onStop()
{
super.onStop();
Log.v(TAG, "onStop");
}
public void onDestroy()
{
super.onDestroy();
Log.v(TAG, "onDestroy");
}
public void onRestart()
{
super.onRestart();
Log.v(TAG, "onReStart");
}
}