0

How to set image in second Activity from first Activity?Please I have a serious Problem with it.Help me for this.

Edit (this has been copied from the comment):

First Activity code for Intent put Extra:

in.putExtra("image", marraylist_image.get(arg2).toString()); 

Second Activity code for Set image in imageview

image = mbundle.getString("image"); 
Bitmap bmp = BitmapFactory.decodeFile(image); 
System.out.println("Image Value:--" + bmp); 
img.setImageBitmap(bmp);
slugster
  • 49,403
  • 14
  • 95
  • 145
Romil
  • 21
  • 1
  • 6
  • 1
    First Activity code for Intent put Extra:in.putExtra("image", marraylist_image.get(arg2).toString()); Second Activity code for Set image in imageview image = mbundle.getString("image"); Bitmap bmp = BitmapFactory.decodeFile(image); System.out.println("Image Value:--" + bmp); img.setImageBitmap(bmp); – Romil Oct 10 '12 at 11:03
  • How you declare marraylist_image? – Hardik Joshi Oct 10 '12 at 11:14
  • check here may it is your solution [click here](http://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles/7890405#7890405) – Jeetu Oct 10 '12 at 11:24
  • check here may it is your solution http://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles/7890405#7890405 – Jeetu Oct 10 '12 at 11:29
  • check this link http://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles/7890405#7890405 – Jeetu Oct 10 '12 at 11:30

2 Answers2

0

Activity1:

bytes[] imgs = ... // your image
Intent intent = new Intent(this, YourActivity.class);
intent.putExtra("img", imgs);
startActivity(intent);

Activity2:

bytes[] receiver = getIntent().getExtra("img");

Also refer This answer.

Community
  • 1
  • 1
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
  • hey please read my first comment.here i used Arralist to add image to listview.I want to display that image in Second Activity in Imageview.] – Romil Oct 10 '12 at 11:12
  • First convert your bitmap to bytes[] then pass it to next activity after that at second activity catch all bytes[] and again convert it to bitmap and display it into your imageview. – Hardik Joshi Oct 10 '12 at 11:13
0

Using bundle you can pass your image to seconfd activity like this :

               intent = new Intent(this, Second.class);
                bundle = new Bundle();
                bundle.putString("imageurl", "your image string");
                intent.putExtras(bundle);
                startActivity(intent);

and in second activity:

 bundle = new Bundle();
                   bundle = getIntent().getExtras();
                   imageurl_of_event = bundle.getString("imageurl");

and for displaying image:

HttpURLConnection conn;
                try {
                    URL feedImage = new URL(imageurl_of_event);
                    conn = (HttpURLConnection) feedImage.openConnection();
                    InputStream is = conn.getInputStream();
                    Bitmap img = BitmapFactory.decodeStream(is);
                    event_imageview.setImageBitmap(img);
}catch.....

thats it

Neha.R
  • 513
  • 3
  • 9