-1

I have One Activity name AlbumPicker. In that activity I am calling below code on Button click.

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra("Example", 40);
((Activity) _ctx).startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"),
                        returnCode); 

Now Gallery will open.

Then i will select one image.

then below method will get called I want Example value in below method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   int example = data.getIntegerExtra("Example);
}

but this code failes. I always recives 0

Please help

Rohan Zemse
  • 49
  • 1
  • 9

1 Answers1

1

You don't have control over the data returned by the Gallery Activity, it's just return its own result intent, so your intent extra is lost. You should use an alternative way to get the value, maybe you can use something like this:

final int yourReturnCode = 3040;
final int yourExampleValue = 40;
Intent intent = new Intent(Intent.ACTION_PICK, 
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
((Activity) _ctx).startActivityForResult(
                    Intent.createChooser(intent, "Select Picture"),
                    yourReturnCode);





protected void onActivityResult(int requestCode, int resultCode, Intent 
              data) {
         int yourValue = 0;
       if (resultCode == yourReturnCode) {
             yourValue = yourExampleValue;
         }
    }
diegoveloper
  • 93,875
  • 20
  • 236
  • 194