新建一个FirstAvtivity.java
package com.zhuguangwei;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;public class FirstActivity extends Activity {
private Button myButton;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.main);myButton = (Button) findViewById(R.id.myButton);myButton.setOnClickListener(new OnClickListener() { @Overridepublic void onClick(View v) { // TODO Auto-generated method stubIntent intent = new Intent();//Intent传递参数intent.putExtra("testIntent", "123");intent.setClass(FirstActivity.this, SecondActivity.class);FirstActivity.this.startActivity(intent);}});}}新建第二个SecondActivity.java
package com.zhuguangwei;
import android.app.Activity;
import android.content.Intent;import android.os.Bundle;import android.widget.TextView;public class SecondActivity extends Activity{
private TextView myTextView;@Overrideprotected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.other);//使用Intent对象得到FirstActivity传递来的参数Intent intent = getIntent();String value = intent.getStringExtra("testIntent");myTextView = (TextView) findViewById(R.id.myTextView);myTextView.setText(value);}}两个Activity都要在AndroidMenifest.xml中注册