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
Try passing id related to image through intent.putExtra(), and receive it through bundle on launched activity.
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)))
Once an item of Grid View
is clicked, get the clicked item and pass it to next activity
as an argument through PutExtra
. In the next activity retrieve the image from extras and display it to user
in Activity convert the image to ByteArray and append it to the intent as
intent.putExtra("img",<ByteArray>);
then startActivity B.
In Activity B
Bitmap bm = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("img"), 0, getIntent().getByteArrayExtra("img").length);
This way you can pass image between activity.
To pass the data between two activities:
bytes[] imgs = ... // your image
Intent intent = new Intent(this, YourActivity.class);
intent.putExtra("img", imgs);
startActivity(intent);
Then in YourActivity:
bytes[] receiver = getIntent().getExtra("imgs");
Also go thro this link which wil also help u.
Here u can know how to convert bitmap to bytes
This is my process: it's so good. Activity1:
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
byte[] byteArray=stream.toByteArray();
Intent intent = new Intent(getApplicationContext(), FrameActivity.class);
intent.putExtra("Image", byteArray);
startActivity(intent);
in FrameActivity.class
collageView = (CollageView) findViewById(R.id.btn_collage);
byte[] byteArray = getIntent().getByteArrayExtra("Image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
collageView.setImageBitmap(bmp);