2

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) {
Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
Nam Nguyen
  • 71
  • 1
  • 8

1 Answers1

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

Community
  • 1
  • 1
vokilam
  • 10,153
  • 3
  • 45
  • 56