0

I have two different strings in different activity passing in another activity and assigning in imageview. How to do this?

   Activity A:

        Intent intent=new Intent(activity,B.class);
        intent.putExtra("thumb_url", Image); // this is Bitmap
        activity.startActivity(intent);

  Activity C:

      Intent intent = new Intent(activity,B.class);
        intent.putExtra("thumb_urls", images)); //this is String
        activity.startActivity(intent);

 Activity B:

         bundle = getIntent().getExtras();
         if(bundle.containsKey("thumb_url") && bundle.containsKey("thumb_urls")
         {
            Bitmap bitmap=bundle.getParcelable("thumb_url");
            String profile=bundle.getString("thumb_urls");
          }
     I don't know how to assign this in same imageview.

                // bigger_image.setImageBitmap(bitmap); // how to assign in same imageview for bitmap and string.
               //  imageLoader.DisplayImage(profile, bigger_image); // 

2 Answers2

0

An if should do the job.

 Bitmap bitmap=bundle.getParcelable("thumb_url");
 String profile=bundle.getString("thumb_urls");
 if(bitmap==null && profile!=null)
     imageLoader.DisplayImage(profile, bigger_image);
 else if(bitmap!=null && profile==null)
     bigger_image.setImageBitmap(bitmap);

Also if you are going to receive different content you shouldn't restrict your if(bundle.containsKey("thumb_url") && bundle.containsKey("thumb_urls"). You should use a || instead of &&.

So the best you can do is:

if(bundle.containsKey("thumb_url"){
  Bitmap bitmap=bundle.getParcelable("thumb_url");
  bigger_image.setImageBitmap(bitmap);
} else if (bundle.containsKey("thumb_urls")){
  String profile=bundle.getString("thumb_urls");
  imageLoader.displayImage(profile, bigger_image); //displayImage instead. DisplayImage doesn't exist.
}
Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
0

you should't pass a Bitmap in Activity, instead, by using a uri

zhaokun
  • 104
  • 2
  • 10