【发布时间】:2020-12-28 08:39:54
【问题描述】:
我知道有很多与此类似的问题,但其中提到的解决方案都不适合我,我不太确定为什么。
我有以下设置:
从MainActivity.java启动:
Button b = findViewById(R.id.btn_b);
b.setOnClickListener(new View.onClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Activity2.class);
startActivityForResult(intent, 0);
}
});
从Activity2.java返回值:
@Override
public onBackPressed() {
System.out.println("Here"); // this can be seen in the logcat
Intent retIntent = new Intent();
// putExtra some return values
setResult(RESULT_OK, retIntent);
finish();
}
在MainActivity.java接收回数据:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("Returning"); // this doesn't fire at all
if (data != null) { // I know there will be no other activities, and I want to act on whatever result I get
// extract and do something with data
}
}
我真的不明白这里发生了什么。有人可以帮忙解释一下,以及如何解决吗?如果需要,我很乐意提供更多信息。
感谢您的宝贵时间。
【问题讨论】:
-
你没有说出问题所在。
标签: java android android-activity