在StartActivityForResult如何从孩子的要求code [英] In StartActivityForResult how to get requestCode from child
问题描述
我有四个活动说A,B,C和D
我的情况是A将通过startActivityForResult启动b活动。
I have Four activity say A, B, C and D
My situation is A will start the activity B by startActivityForResult.
startActivityForResult(new Intent(this,B.class),ONE);
在其他情况下,我将与其他情况B点。像
In other situation i will B with other situation. like
startActivityForResult(new Intent(this,B.class),TWO);
在B I需要检查我需要调用C或D取决于请求code。如果即ONE需要启动C否则ð
所以,我需要知道谁(在这里B)检查请求code在孩子活动
或者换句话说,我想要得到什么要求code没有B则在b活动
在此先感谢
In B i need to check I need to call C or D depending requestCode. I.e if ONE need to start C else D
So i need to know who to check the requestCode in the child Activity (B here )
Or in other words I want to get with what request code did B started in the Activity B
Thanks in advance
推荐答案
您可以把多余的传递请求code。
You can pass request code by put extra.
intent.putExtra("requestCode", requestCode);
或者,如果你已经使用 startActivityForResult
很多次,那么比编辑每个较好,可以覆盖
的 startActivityForResult
在活动
,添加code有这样
Or if you have used startActivityForResult
many times, then better than editing each, you can override
the startActivityForResult
in your Activity
, add you code there like this
@Override
public void startActivityForResult(Intent intent, int requestCode) {
intent.putExtra("requestCode", requestCode);
super.startActivityForResult(intent, requestCode);
}
因此,有没有需要修改所有startActivityForResult
希望它帮助你。
So there is no need to edit all your startActivityForResult
Hope it helped you
这篇关于在StartActivityForResult如何从孩子的要求code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!