0

In my First activity I have list of bitmaps stored in ArrayList of type Bitmap, I need same list for my Second Activity. How can I achieve that?

Please help!

Arjun G
  • 606
  • 1
  • 7
  • 20
  • 1
    you can't pass it via Intent because it's size is limited. You can use some static variable, or save them to the files, and pass arraylist of file names instead – Vladyslav Matviienko Aug 01 '17 at 10:44
  • you can use the path of the image and use that in second activity. – Raghunandan Aug 01 '17 at 10:45
  • Hello raghunandan I'm not saving images as files! – Arjun G Aug 01 '17 at 10:47
  • not a duplicate, it's very likely that a list of bitmap won't fit into the intent – lelloman Aug 01 '17 at 10:50
  • can you show us (code) what you are doing. – Raghunandan Aug 01 '17 at 10:55
  • Intent intent = new Intent(MainActivity.this, GeneratedBarCodes.class); intent.putParcelableArrayListExtra("BAR_CODES_LIST", listOfBarCodes); startActivity(intent); – Arjun G Aug 01 '17 at 10:57
  • read Vlad Matvienko comment again. i am not sure of the limit. it could be 1MB. So you need to store the bitmap some where and use the path. – Raghunandan Aug 01 '17 at 10:58
  • Remember Bitmaps will contain huge data and it is bad idea to pass it through intents. While you have array of bitmaps will contain unimaginable amount of data where the intent cannot handle to pass it to next activity. Its better to use Uri path to set the images. – SripadRaj Aug 01 '17 at 11:03

1 Answers1

0

Create Pojo class with required fields which u need to pass to next Activity as follows : In Android Studio window use windows+Insert key to generate getter,setter and Parcelable methods.

public class PojoClass {
    private String name;
    private String id;
    private String place;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPlace() {
        return place;
    }
    public void setPlace(String place) {
        this.place = place;
    }
}

Set the values to pojo class:

Intent intent = new Intent(this,NextActivity.class);
    intent.putExtra("Data", pojoclass);
            startActivity(intent);

In Next Activity
ArrayList arrayList = getIntent().getParcelableExtra("Data");

Jeelan
  • 173
  • 1
  • 11