0

I have two classes A and B,I have used intent to pass the array text values from A to B successfuly.However I have two issues with process.

1- I can't send my images throught the intent.

2- I can't display the recieved values in class B.

How can I achieve this.

Here what I have done so far.

Class A:

       @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    Intent in = new Intent(this,
            Mahad.class);       

    in.putExtra("temp_image", image);       
    in.putStringArrayListExtra("temp_identifier", identif);     
    in.putStringArrayListExtra("temp_price", price);        
    in.putStringArrayListExtra("temp_bedrooms", bedrooms);      
    in.putStringArrayListExtra("temp_address", address);    
    in.putStringArrayListExtra("temp_propType", propType);  

    startActivity(in);
}

Class B:

    identif = getIntent().getExtras().getStringArrayList("temp_identifier");
    price = getIntent().getExtras().getStringArrayList("temp_price");
    bedrooms = getIntent().getExtras().getStringArrayList("temp_bedrooms");
    address = getIntent().getExtras().getStringArrayList("temp_address");
    propType = getIntent().getExtras().getStringArrayList("temp_propType");

    image = getIntent().getByteArrayExtra("temp_image");//Not working
SomCollection
  • 481
  • 1
  • 7
  • 17

2 Answers2

0

Is image a Bitmap? If so it implements Parcelable which means you want to do getIntent().getParecelableExtra("temp_image"); Here is the JAVADOC: http://developer.android.com/reference/android/content/Intent.html#getParcelableExtra(java.lang.String)

Salil Pandit
  • 1,498
  • 10
  • 13
  • Salil,I have already tried using this method however its crashing all the time with the result of :E/JavaBinder(346): !!! FAILED BINDER TRANSACTION !!!....not sure what that is. – SomCollection Feb 24 '12 at 23:04
0

Intents pass data in the form of Bundles. So, I am sure this should get you to do what you're trying to do: how do you pass images (bitmaps) between android activities using bundles?

Alternatively, you could break the image into byte[] using the BitmapFactory API and use that to pass inside of Intents.

However, please be advised that all these are memory intensive operations and not the ideal practice. Instead, your source Activity should save the images to files and pass a ArrayList containing the file names and their corresponding mappings to the destination Activity using Intents. I had a similar use case in the past and trust me, passing image objects via Intents WILL cause OutOfMemoryErrors for you sooner or later as the heap will keep growing to a certain threshold and eventually the DVM won't allow it to grow any further and kill your app.

Community
  • 1
  • 1
Sagar Hatekar
  • 8,700
  • 14
  • 56
  • 72
  • Sagar,Thanks for your extended solution as suggested I have my images comming from database as Byte[] and I can display them into Class A but just need to display in Class B. – SomCollection Feb 24 '12 at 22:45
  • Yes, so you could instead pass the db query selection/project string to Class B and then retrieve the same set of images in Class B. Alternatively, you could pass the byte[] via Intent. – Sagar Hatekar Feb 24 '12 at 22:57
  • BTW, your DB is going to inflate ALOT if you keep adding additional images. My advise is to store the images into files and store the filenames into db. I've tried storing entire BLOBs/byte[]s in to db and it's really not very efficient. You might have to do minor refactoring. – Sagar Hatekar Feb 24 '12 at 22:59
  • That is actualy very good advice,where and how can I undertake this process any tutorials can you help.Seems you have had some experience in BLOB images what do you suggest so that I can get out of this problem. – SomCollection Feb 24 '12 at 23:09