setResult does not work when BACK button pressed

前端 未结 10 1935
南方客
南方客 2020-11-27 13:08

I am trying to setResult after the BACK button was pressed. I call in onDestroy

Intent data = new Intent();
setResult(RESULT_OK, data) 

But

10条回答
  •  醉酒成梦
    2020-11-27 13:54

    If you want to set some custom RESULT_CODE in onBackPressed event then you need to first set the result and then call the super.onBackPressed() and you will receive the same RESULT_CODE in the caller activity's onActivityResult method

        @Override
        public void onBackPressed()
        {
             setResult(SOME_INTEGER);
             super.onBackPressed();
        }
    

提交回复
热议问题