Activity A 生成 Activity B 若A想得到B的数据,则B需要作为A的subActivity 则需要在 Activity A中调用startActivityForResult(Intent,int); //Intent int为标识码 requestCode 然后 在Activity A 中重写 onActivityResult(int requestCode,int resultCode,Intent data) 判断requestCode 与之前startActivityForResult()传入的标识码是否相同,再判断resultCode 是否正常, 在Activity B 完成finish() 函数后 ,会回调onActivityResult(); protected void onActivityResult(int requestCode,int resultCode,Intent data){ if((requestCode ==request_code) && (resultCode == RESULT_OK)){ TextView textView1 = (TextView) findViewById(R.id.textView1); String returnString=data.getExtras().getString("returnData"); textView1.setText(returnString); } } public void finish() { Intent data = new Intent(); EditText editText1=(EditText)findViewById(R.id.editText1); String returnString =editText1.getText().toString(); data.putExtra("returnData", returnString); setResult(RESULT_OK,data); super.finish(); }
1200字范文,内容丰富有趣,写作的好帮手!