错误的requestCode从另一个活动返回了onActivityResult [英] Wrong requestCode returned onActivityResult from another Activity
问题描述
我有一个 Activity
,它调用了另一个 Activity
,又调用了其他 Activity
.我发送到最后的 Activity
以获得结果,然后将结果发送回第一拳头 Activity
.
I have an Activity
that calls another Activity
, that calls some other Activities
.
I send to the last Activity
to get a result, and then i send back the result to the fist Activity
.
流量真像
A -> B -> C -> D -> C -> B -> A
从 A
到 D
的流程由 startActivityForResult
组成,从 D
到的流程组成> A
由 onActivityResult
组成.
With the flow from A
to D
is made of startActivityForResult
and the flow from D
to A
is made of onActivityResult
.
从 D
到 B
, requestCode
始终相同(我决定的那个),但是从 B
变成 A
,它突然从我的值变成了随机值(在这种情况下为196614).
From D
to B
the requestCode
is always the same (the one I decided), but from B
to A
it suddenly change from my value to a random value (in this particular case 196614).
这是我用来从 activity A
调用 activity B
的代码:
This is the code I use to call the activity B
from activity A
:
filterByCatalogue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CatalogueContainerActivity.class);
startActivityForResult(intent, Defines.FILTER_BY_CATALOGUE);
}
});
(使用 filterByCatalogue
作为 FrameLayout
)
这是我用来调用活动A
的代码:
This is the code I use to call back the activity A
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Defines.FILTER_BY_CATALOGUE) {
if (resultCode == RESULT_OK) {
Intent intent = new Intent();
intent.putExtra("article", data.getStringExtra("article"));
setResult(RESULT_OK, intent);
finish();
}
}
}
我已经搜索了很多,但是找不到错误的地方....
I've searched a lot but I can't find where I go wrong....
推荐答案
只需替换
startActivityForResult(intent, Defines.FILTER_BY_CATALOGUE);
使用
getActivity().startActivityForResult(intent, Defines.FILTER_BY_CATALOGUE);
它肯定会工作.:)
这篇关于错误的requestCode从另一个活动返回了onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!