一,activity跳转携带参数
AActivity跳BActivity,A给B传递数据,B接受
AActivity界面:
BActivity.actionStart(AActivity.this, id);//id:传递的参数
BActivity界面
private int id;
//接收上个页面的数据
private void initData() {
this.id = getIntent().getIntExtra("id", 0);
}
public static void actionStart(Context context, int id) {
Intent intent = new Intent();
intent.putExtra("id", id);
intent.setClass(context, BActivity.class);
context.startActivity(intent);
}
二,activity跳转返回传值
AActivity跳BActivity,A给B传递数据,B返回给A自己页面的数据,A显示
REQUEST_CODE:请求码
RESULT_OK:返回码
AActivity:
startActivityForResult(newIntent(this,BActivity.class).putExtra("id",id),REQUEST_CODE); //putExtra:A向B传递一些数据
//接收B传递过来的参数的方法
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_CODE:
quota= data.getStringExtra("quota");
tv.setText(quota);
break;
}
BActivity:
//获取A传递过来的参数(putExtra)
private void getIntentData() {
businessId=getIntent().getLongExtra("id",0);
}
//向A返回数据
setResult(RESULT_OK,new Intent().putExtra("quota",quota));