Fragments startActivityForResult always return resultCode 0 and intent null on callback onActivityResult

主宰稳场 提交于 2019-11-28 13:57:21

Result code 0 is RESULT_CANCELLED.

The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

Also the common reason of getting this code is a launching an activity in a new task (check your intent and manifest for flags, which lead to the start of a new task).

Also if you have a parent activity, you should set result code of it instead of set result code of its child (try to getParent and if it is not null, than set result code of it).

Harri Westman

I spent some time to find out the reason. My mistake was put super.onBackPressed() in the onBackPress() method.

I called finish() in the method. But I think super.onBackPressed() will call the finish() automatically so you will get resultCode 0 always. So just remove the super.onBackPressed() line in the onBackPressed() method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!