在MainActivity中:
public class MainActivity extends Activity {
EditText et_name,et_sex,et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_name=(EditText) findViewById(R.id.et_name); et_sex=(EditText) findViewById(R.id.et_sex); et_number=(EditText) findViewById(R.id.et_number); }public void onclick(View v)
{ String name=et_name.getText().toString().trim(); String sex=et_sex.getText().toString().trim(); String number=et_number.getText().toString().trim(); if(TextUtils.isEmpty(name)&&TextUtils.isEmpty(number)&&TextUtils.isEmpty(sex)) { Toast.makeText(this, "姓名性别手机号不能为空", 0).show(); return; } Intent intent=new Intent(); intent.setClass(this,MyActivity.class); //1.1这种方式只能传递一个信息// intent.putExtra("name", name); //1.2 Bundle bundle=new Bundle();//用作捆绑较多的信息 bundle.putString("name", name); bundle.putString("sex", sex); bundle.putString("number",number); intent.putExtras(bundle); startActivity(intent); }}
在自定义的MyActivity中(要在清单文件中注册页面):
public class MyActivity extends Activity {
TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.myactivity); tv=(TextView) findViewById(R.id.tv); Intent intent=this.getIntent();//返回激活这个Activity的intent Bundle bundle=intent.getExtras(); String name=bundle.getString("name"); String sex=bundle.getString("sex"); String number=bundle.getString("number"); String text="您的信息为:"+"\n"+"姓名:"+name+"\n"+"性别:"+sex+"\n"+"手机号:"+number; tv.setText(text); }}