Search code examples
androidonactivityresult

intentChooser returns odd requestCode


I am trying to catch the response from the share chooser which sends email attachment so I know when I will delete the file from the sdcard.

The intentChooser is called from the Fragment

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"email"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    intent.putExtra(Intent.EXTRA_TEXT, "body");

    Uri uri = Uri.fromFile(file);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivityForResult(Intent.createChooser(intent, "Send..."), Consts.SHARE_INTENT);

Where SHARE_INTENT is public static final int SHARE_INTENT = 2;

Then in the Activity which holds this Fragment, I try to catch the response via

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {   

    if (requestCode == Consts.SHARE_INTENT) {
        if (resultCode == RESULT_OK) {
                //do something
        }

        if (resultCode == RESULT_CANCELED)
            Toast.makeText(this, "Share cancelled", Toast.LENGTH_SHORT).show();
    }
}

Then I open the share chooser and cancel it touching outside it, but then I do not catch 4 as requestCode, but I get some odd number like 144563.

Anyone gets any ideas why is this happening?


Solution

  • As stated in this answer https://stackoverflow.com/a/6147919/437039, I accidentally deleted a call to super.onActivityResult(requestCode, resultCode, data).

    Anyone with a similar issue, check the answer I linked here.