How to return a result through multiple activities

前端 未结 4 1666
南方客
南方客 2020-12-12 13:59

in some part of my application there is a structure of activities like this:

\"enter<

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 14:16

    Yup, great formatting. And you can -- and probably should -- definitely call startActivityForResult() from each of Activity A, B, and C (and don't finish() right away). In B and C you can check for a successful result and finish(), passing the result on back to A.

        @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if((resultCode == RESULT_OK) && (requestCode == MY_RESULT_CODE)) {
            setResult(RESULT_OK, data);
            finish();
        }
    }
    

    If you want B and C to disappear regardless, do the following instead:

        @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        setResult(resultCode, data);
        finish();
    }
    

提交回复
热议问题