setResult does not work when BACK button pressed

前端 未结 10 1919
南方客
南方客 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:33

    i paste the answer may be will be helpful to other people: when a set launcheMode with android:launchMode="singleTask" i also cant get the result, the doc says:

         /* 

    Note that this method should only be used with Intent protocols * that are defined to return a result. In other protocols (such as * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may * not get the result when you expect. For example, if the activity you * are launching uses the singleTask launch mode, it will not run in your * task and thus you will immediately receive a cancel result. */

    and:

         /* 

    As a special case, if you call startActivityForResult() with a requestCode * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your * activity, then your window will not be displayed until a result is * returned back from the started activity. This is to avoid visible * flickering when redirecting to another activity. */

提交回复
热议问题