在StartActivityForResult如何从孩子的要求code孩子、StartActivityForResult、code

2023-09-03 20:53:39 作者:幼稚园萌小疯

我有四个活动说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