红糖糍粑
你想要的是什么startActivityForResult()。当你走的时候C到D的,而不是使用,startActivity()使用替代startActivityForResult()。然后,当你想要返回时D,C你可以使用setResult()包含一个可以传回的Intent对象。extrasC我不建议这样做的onBackPressed(),如果你不具备,因为这不会是用户期望的结果。相反,您应该使用诸如Button点击之类的事件返回此数据。所以,C你会做类似的事情 Intent i = new Intent(new Intent(C.this, D.class);
startActivityForResult(i, 0);然后在D你准备好回来的时候 Intent i = new Intent();
i.putExtra(); // insert your extras here
setResult(0, i);然后当你返回时,C你将输入这个方法(取自Docs)protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
// A contact was picked. Here we will just display it
// to the user.
startActivity(new Intent(Intent.ACTION_VIEW, data));
/*
can also get the extra sent back through data
using data.getStringExtra("someKey");
assuming the extra was a String
*/
}