使用Inten的putExtra传递
第一个Activity中
//创建意图对象
Intent intent = new Intent(this,TwoActivity.class);
//设置传递键值对
intent.putExtra("data",str);
//激活意图
startActivity(intent);
第二个Activity中
// 获取意图对象
Intent intent = getIntent();
//获取传递的值
String str = intent.getStringExtra("data");
//设置值
tv.setText(str);
使用Intention的Bundle传递
第一个Activity中
//创建意图对象
Intent intent = new Intent(MainActivity.this,TwoActivity.class);
//用数据捆传递数据
Bundle bundle = new Bundle();
bundle.putString("data", str);
//把数据捆设置改意图
intent.putExtra("bun", bundle);
//激活意图
startActivity(intent);
第二个Activity
//获取Bundle
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("bun");
String str = bundle.getString("data");
tv.setText(str);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。