Activity result is always 0

佐手、 提交于 2019-12-12 21:38:53

问题


I search whole day for this issue:

mUploadImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");

            startActivityForResult(
                    Intent.createChooser(intent, "Select a Picture"),
                    FILE_SELECT_CODE);
        }
    });

Whenever I click on mUploadImage OnActivityResult() method it will be triggered immediately (Although i dont choose any file yet) and result code always 0. can anyone help me?

EDIT: (from comment below)

protected void onActivityResult(int arg0, int arg1, Intent arg2) {
    if (arg0 == FILE_SELECT_CODE) {
        Log.v(TAG, "Selected a image. Result code: " + arg1);
        if (arg1 == Activity.RESULT_OK) {

回答1:


Check these answers. All of them say that there's a dependence between activity's launchMode and reporting result immediately

onActivityResult() called prematurely

Android - startActivityForResult immediately triggering onActivityResult

onActivityResult() is being called at an unexpected time



来源:https://stackoverflow.com/questions/15199404/activity-result-is-always-0

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