1

I got this image from the server. The image is not in the project resource folder. The text is working correctly, but the image is not showing in another activity.

    MyAdapter objAdapter1;
listView.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            Item item = (Item) objAdapter1.getItem(position);



            Intent intent = new Intent(ChooseDriver.this, DriverDetail.class);
            intent.putExtra(ID, item.getId());
            intent.putExtra(NAME, item.getName().toString());
           intent.putExtra(IMAGE, item.getImage().toString());



            image.buildDrawingCache();
            Bitmap image= image.getDrawingCache();

             Bundle extras = new Bundle();
           extras.putParcelable("imagebitmap", image);
            intent.putExtras(extras);

            startActivity(intent); 
        }
    });
David
  • 15,894
  • 22
  • 55
  • 66
  • possible duplicate of [How can I pass a Bitmap object from one activity to another](http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another) – jpros May 11 '14 at 05:21
  • 1
    You can see the answer [here](http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another) – jpros May 11 '14 at 05:22
  • intent.putExtra("image",byteArray); should work – techieWings May 11 '14 at 05:30
  • friends I get image from web.not in local resources.So I use this adapter for retrive.any one give solution. –  May 11 '14 at 05:45
  • Show the code for the second Activity where you try to get the image. – Squonk May 11 '14 at 06:43
  • In first Activity, Item item = (Item) objAdapter1.getItem(position); Bitmap bmp =(Bitmap) item.getImage; intent.putExtra("YourBitmap", bmp); In Second Activity, Bitmap bitmap =(Bitmap)intent.getParcelableExtra("YourBitmap"); imageView.setImageBitmap(bitmap); –  May 11 '14 at 08:18

2 Answers2

1

In FirstActivity,

Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("YourBitmap", bitmap);

and in SecondActivity,

Intent intent = getIntent();
Bitmap bitmap = (Bitmap)intent.getParcelableExtra("YourBitmap");

May it help you.

PageNotFound
  • 2,320
  • 2
  • 23
  • 34
1

try this:

Main Activity:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
mItem.getIcon().compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
newIntent.putExtra("image", byteArray);

Second Activity:

byte[] byteArray = getIntent().getExtras().getByteArray("image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
img.setImageBitmap(bmp);
The Badak
  • 2,010
  • 2
  • 16
  • 28