为什么我会收到错误的请求,code?我会、错误、code

2023-09-05 01:57:45 作者:Lonely.(孤独)

我有,我用一个活动 startActivityForResult(意向,634)。如果我用它的活动,请求code。在 onActivityResult()是好的。但是,如果我用 startActivityForResult(意向,634)从我在这个活动DialogFragment,我收到另一个请求code,像66170.那么,为什么它的发生?

I have an Activity in which I use startActivityForResult(intent,634). If I using it from activity, requestCode in onActivityResult() is Ok. But if I use startActivityForResult(intent,634) from my DialogFragment in this Activity, I'm getting another requestCode, something like 66170. So why its happens?

推荐答案

这是一个愚蠢的问题。但对于别人谁运行到同样的问题我张贴的答案。

It was a stupid question. But for anyone else who runs into the same "problem" I'm posting the answer.

它的发生,因为如果你使用 startActivityForResult 从对话框,在 onActivityResult 你请求code对话框。不从你的其它活动。如果你想获得正确的请求code,你应该使用 getActivity()。startActivityForResult(意向,要求code)在DialogFragment。

It's happens because if you use startActivityForResult from the dialog, in onActivityResult you get the requestCode of the dialog. Not from your another Activity. And if you want to get right requestCode, you should use getActivity().startActivityForResult(intent,requestCode) in DialogFragment.