第二个活动上的“setResult”要么没有在第一个活动中将数据传递回 onActivityResult,要么甚至没有调用 onActivityResult ......我不知道是哪个
第一个活动:
//-- Handle item selection
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent i = new Intent(this, Options.class);
Bundle counters = new Bundle();
counters.putInt("plWin", plWin);
counters.putInt("plLoss", plLoss);
counters.putInt("plDraw", plDraw);
i.putExtras(counters);
startActivityForResult(i, RESULT_OK);
return true;
case R.id.menu_reset:
//-- Data being passed from "Options" --
protected void onActivityResult(int requestCode, int resultCode, Intent i){
Bundle counts = i.getExtras();
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "BOOM SHAKA LAKA!",Toast.LENGTH_SHORT).show();
plWin = counts.getInt("Win", 100);
plLoss = counts.getInt("Loss", 100);
plDraw = counts.getInt("Draw", 100);
}
}
}
第二个活动:
}
//-- Data being passed back to "Main" --
public void onBackPressed() {
Bundle counters = new Bundle();
Intent i = new Intent();
counters.putInt("Win", wins);
counters.putInt("Loss", losses);
counters.putInt("Draw", draws);
i.putExtras(counters);
setResult(RESULT_OK, i);
finish();
}
}