-2

In my app, I use default album app for get image.

Select image, I set that image at imageview in gridView.

public void getImageFromAlbum(int position){
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(MediaStore.Images.Media.CONTENT_TYPE);
    startActivityForResult(intent, PICK_IMAGE_FROM_ALBUM);
}

I need 'position' value in onActivityResult

If I use my custom activity, I use putExtra. but this case, it can't. I think position value save class value. it will be run, but I don't want it...


Solved

I just use global variable. it's so easy way. I think it's not perfect solution, but it works perfect.

Community
  • 1
  • 1
Redwings
  • 540
  • 2
  • 4
  • 12
  • 1
    Possible duplicate of [How to manage \`startActivityForResult\` on Android?](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – G. Kalender Feb 14 '18 at 12:50
  • @G. Kalender that is 'custom activity' case. isn't it? – Redwings Feb 14 '18 at 12:52
  • https://stackoverflow.com/questions/13023788/how-to-load-an-image-in-image-view-from-gallery – ADM Feb 14 '18 at 12:55
  • @ADM i already know how to get imagefile. that answer is not useful for me.... – Redwings Feb 14 '18 at 13:01

2 Answers2

0
public void getImageFromAlbum(int position){
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(MediaStore.Images.Media.CONTENT_TYPE);
    intent.putExtra("bundle_id",position);
    startActivityForResult(intent, PICK_IMAGE_FROM_ALBUM);
}
  • if i use this, i will write some code in starting activity. but my case, i use default album app, i cant it! – Redwings Feb 14 '18 at 17:13
0
        public void getImageFromAlbum(int position){
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType(MediaStore.Images.Media.CONTENT_TYPE);
            intent.putExtra("bundle_id",position);
            startActivityForResult(intent, PICK_IMAGE_FROM_ALBUM);
        }                                                               
    Get it in your onActivityresult like this :                                 
   int position = data.getIntExtra("bundle_id", -1); use it as your requirment.
Anil Atri
  • 68
  • 8