传递方:
//点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText()
private void setListeners()
{
btn_sub.setOnClickListener(calrBMI);
}
private OnClickListener calrBMI = new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("key_height", fieldHeight.getText().toString());
bundle.putString("key_weight", fieldWeight.getText().toString());
intent.setClass(ActivityMain.this,Report.class);
intent.putExtras(bundle);
startActivity(intent);
}
};
接收方:
Bundle bundle = new Bundle();
bundle = this.getIntent().getExtras();
double height = Double.parseDouble(bundle.getString("key_height"))/100;
double weight = Double.parseDouble(bundle.getString("key_weight"));
本文介绍了在Android应用中如何使用Intent和Bundle在不同Activity之间传递数据。通过示例代码展示了如何从一个Activity向另一个Activity发送字符串类型的参数,并在接收方获取这些数据。

1万+

被折叠的 条评论
为什么被折叠?



