How to pass image data from one activity to another activity?

I am using two activities. One activity displays images in a GridView and by clicking on a particular image in that GridView it should display the full screen image in another activity.

How can I achieve this?

My MyGridView.java

mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), "Image"+(position+1),Toast.LENGTH_SHORT).show();
    System.out.println(id);
    Intent i = new Intent(this, MyImageViewActivity.class);
    Bundle bundle = new Bundle();
    bundle.putInt("image", position);
    i.putExtras(bundle);
    startActivityForResult(i, 0);
}
});

Pass the image URL/Uri instead of passing raw image data.


In MyGridView: (someInteger is an integer that represents the index of the selected image

Intent myIntent = new Intent(this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("image", someInteger);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);

In MyImageViewActivity:

Bundle bundle = this.getIntent().getExtras();
int pic = bundle.getInt("image");

of course, you can put anything in the bundle! maybe a byte array or something


You pass parameters to an Activity in an Intent. If the image comes from a file, pass the path String, otherwise pass the Bitmap

startActivity(new Intent(this, YourActivity.class).putExtras(new Bundle().putParcelable("bitmap", Bitmap)))