当前位置:文档之家› ANDROID实验报告生命周期

ANDROID实验报告生命周期

@Override protected void onResume() {
// TODO Auto-generated method stub super.onResume(); System.out.println("AlcActivity2:onResume()"); }
@Override protected void onStart() {
递 Bundle bundle = new Bundle(); bundle.putString("NAME", name); bundle.putInt("AGE", age); intent.putExtras(bundle); //用 startActivityForResult()方法取代 startAcctivity()方法将包里寄出,
@Override //接收被调程序传回的数据,必须重载 onActiveResult()方法。
protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub
4、通络 Intent 实现多页面之间数据的传递(辅助完成)。
二、 实验内容
1、 搭建任意组件,设计多个界面,运行程序观察其生命周期的
情况。
2、 使用Hale Waihona Puke Intent 实现页面之间数据的传递。
三、 实验代码
AlifecyfleActivity.java package com.wr; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;
// TODO Auto-generated method stub Intent intent = new Intent(AlifecycleActivity.this,AlcActivity2.class);//创建意 图对象
//使用意图对象打开一个新的 Activity startActivity(intent); } } } AlcActivity.java package com.wr;
// TODO Auto-generated method stub super.onPause(); System.out.println("AlcActivity2:onPause()"); }
@Override protected void onRestart() {
// TODO Auto-generated method stub super.onRestart(); System.out.println("AlcActivity2:onRestart()"); }
import android.app.Activity; import android.os.Bundle;
public class AlcActivity2 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(yout.alcactivity2_main); }
// TODO Auto-generated method stub super.onStart(); System.out.println("AlcActivity2:onStart()");
}
@Override protected void onStop() {
// TODO Auto-generated method stub super.onStop(); System.out.println("AlcActivity2:onStop()"); }
} IntentActivity.java
package com.gml;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView;
Android 开发
(实验四)
实验题目:Activity 生命周期验证试验 指导老师: 班 级:计算机科学与技术系班 姓 名:(
一、 实验目的
1、深入理解 Activity 运行机制和原理。
2、掌握 Activity 的声明周期各个阶段工作流程。
3、掌握多个 Activity 之间生命周期的转换过程。
并等待另一方的回音。 startActivityForResult(intent,ACTIVITY_EDIT);
} }; } OneActivity.java package com.gml;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;
@Override protected void onPause() {
// TODO Auto-generated method stub super.onPause(); System.out.println("AlifecycleActivity:onPause()"); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); System.out.println("AlifecycleActivity:onRestart()"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); System.out.println("AlifecycleActivity:onResume()"); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); System.out.println("AlifecycleActivity:onStart()"); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); System.out.println("AlifecycleActivity:onStop()"); } public class MyBtnClickListener implements OnClickListener { //重写点击事件处理方法 public void onClick(View arg0) {
public void onClick(View v){ Intent intent = new Intent(); //使用 setClass()确定 Intent 的发件人和收件者,IntentActivity 传递给
Second. intent.setClass(IntentActivity.this, OneActivity.class); //使用 Bundle 对象的 put()方法打包数据,并利用 putExtras()来进行传
public class IntentActivity extends Activity { private TextView txtShow; private Button btnPage2; private String name; private int age;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {
super.onActivityResult(requestCode, resultCode, data); if(requestCode==ACTIVITY_EDIT){
if(resultCode==RESULT_OK){ Bundle bundle = data.getExtras(); age = bundle.getInt("AGE"); String s= "姓名:"+name+"\n\r"+"年龄:"+age; txtShow.setText(s);
public class AlifecycleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(yout.main); Button BtnStart = (Button) findViewById(R.id.BtnStart); BtnStart.setOnClickListener(new MyBtnClickListener()); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); System.out.println("AlifecycleActivity:onDestroy()"); }
相关主题