a:传值
Intent intent = new Intent(this,secondActivity.class); String text =editText.getText().toString(); intent.putExtra(Intent_key,text);//a传b在此处写你传的值
startActivityForResult(intent,0);//此处的requestCode应与下面结果处理函中调用的requestCode一致
a接收b的值:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==0 && resultCode==RESULT_OK){ Bundle bundle = data.getExtras(); if(bundle!=null) text=bundle.getString("second");//这里接收b的值做处理 } }
b接收a的值:
Intent intent =getIntent(); String text =intent.getStringExtra(MainActivity.Intent_key);
b回传给a
Intent intent =getIntent(); //这里使用bundle绷带来传输数据 Bundle bundle =new Bundle(); //传输的内容仍然是键值对的形式 bundle.putString("传的建","传的值!");//回发的消息,hello world from secondActivity! intent.putExtras(bundle); setResult(RESULT_OK,intent); finish();