在第二个活动中,您可以使用方法getIntent()获取第一个活动的数据,然后使用getStringExtra(),getIntExtra()…
然后要返回到第一个活动,您必须使用setResult()方法将intent数据作为参数返回.
要在第一个活动中获取第二个活动的返回数据,只需覆盖onActivityResult()方法并使用intent获取数据.
第一项活动:
//In the method that is called when click on "update"
Intent intent = ... //Create the intent to go in the second activity
intent.putExtra("oldValue","valueYouWanttochange");
startActivityForResult(intent,someIntValue); //I always put 0 for someIntValue
//In your class
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
//Retrieve data in the intent
String editTextValue = intent.getStringExtra("valueId");
}
第二项活动:
//When activity is created
String value = intent.getStringExtra("oldValue");
//Then change the editText value
//After clicking on "save"
Intent intent = new Intent();
intent.putExtra("valueId",value); //value should be your string from the edittext
setResult(somePositiveInt,intent); //The data you want to send back
finish(); //That's when you onActivityResult() in the first activity will be called
不要忘记使用startActivityForResult()方法开始第二个活动.