Skip to content Skip to sidebar Skip to footer

Onactivityresult Not Getting Called While Using Gallery In Android

I am opening a gallery in my Android Application using this code. Intent intent = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI); intent.addFlags(Intent.FLAG_ACTIVITY_

Solution 1:

There are lot of possibilities for onActivityResult() not triggered.

  • If your request code is < 0
  • If you have android:launchMode="singleInstance" set in the Manifest.xml
  • If you are using fragments then you must call the Fragment's startActivityOnResult instead of Activity's

Solution 2:

I added this Method in Parent class like this

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    ProductImageActivityactivity= (ProductImageActivity)getLocalActivityManager().getCurrentActivity();
    try {
        activity.onActivityResult(requestCode, resultCode, data,0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

and in my current class I started new Intent like this.

Intentintent=newIntent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
getParent().startActivityForResult(intent, GALLERY);

Solution 3:

Check http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK for the behavior of Intent.FLAG_ACTIVITY_NEW_TASK. It is used for independent activities.

This flag is generally used by activities that want to present a "launcher" style      behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them.

Removing that line, you will get a call to onActivityResult once a image is selected.

Intentintent=newIntent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, GALLERY);

Solution 4:

Try this & use Intent Like this For Fetching Image From Gallery

Intentintent=newIntent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, GALLERY);  

Or

Intentintent=newIntent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, GALLERY);

Post a Comment for "Onactivityresult Not Getting Called While Using Gallery In Android"