android中的setResult()有时无法将正确的结果代码传递给其他活动
这是我的密码android中的setResult()有时无法将正确的结果代码传递给其他活动,android,android-activity,onactivityresult,Android,Android Activity,Onactivityresult,这是我的密码 if (onApply) { Intent intent = new Intent(); setResult(200, intent); super.onBackPressed(); } else { Intent intent = new Intent(); setResult(RESULT_OK, intent); super.onBackPressed(); }
if (onApply) {
Intent intent = new Intent();
setResult(200, intent);
super.onBackPressed();
} else {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
super.onBackPressed();
}
不是每次,但有时我在onActivity结果中得到结果代码0
提前感谢。通常,您可以忽略某个地方调用finish()而不调用setResult()的情况
顺便说一句,RESULT_cancelled=0是默认值,因为从未调用过setResult()。使用
super.onBackPressed()有具体原因吗
而不是finish()
?因为我在finish()上也遇到了相同的错误。可能是用户按下了后退按钮。