在原界面里创建Intent的添加数据,以及需要跳转的界面
//点击按钮进行页面的跳转 btnToA01.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //获取电话号码 String strtel = ""; strtel = etTel.getText().toString(); //获取短信内容 String strSMS = ""; strSMS = editMes.getText().toString(); //初始化Intent对象,并把需要传递的数据放到intent中 Intent intent = new Intent(MainActivity.this,A02Activity.class); intent.putExtra("Tel",strtel); intent.putExtra("Sms",strSMS); startActivity(intent); } });
在需要跳转的界面:
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_a01); btnBack = (Button)findViewById(R.id.btnBack) ; tvMsg = (TextView)findViewById(R.id.tv_message); //获取intent Intent intent = null; intent = getIntent(); //获取数据 String strTel = ""; String strSms = ""; strTel = intent.getStringExtra("Tel"); strSms = intent.getStringExtra("Sms"); tvMsg.setText("电话号:" + strTel + "短信内容:" + strSms); btnBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
来源:https://www.cnblogs.com/1gaoyu/p/12554149.html