My problem is after i pass the list to second activity i can not cast it to list back. Its crashing app.I tried with try catch but still no exception. Any idea what im doing wrong ? Tyvm.
Activity 1
private ArrayList<ResimBean> rbList = new ArrayList<ResimBean>();
Intent intent = new Intent(getApplicationContext(), ResimListActivity.class);
intent.putParcelableArrayListExtra("reslist",rbList);
startActivityForResult(intent, 100);
Activity 2
private ArrayList<ResimBean> rbList = new ArrayList<ResimBean>();
if (extras != null) {
try {
Intent i = getIntent();
rbList = (ArrayList<ResimBean>)i.getParcelableArrayListExtra("reslist");
} catch (Exception ex) {
String msg = ex.getMessage();
}
}
And My Class
public class ResimBean implements Parcelable {
private int Id;
private int HataBildirimId;
private byte[] Resim;
private byte[] Thumbnail;
public byte[] getThumbnail() {
return Thumbnail;
}
public void setThumbnail(byte[] thumbnail) {
Thumbnail = thumbnail;
}
private String Path;
public String getPath() {
return Path;
}
public void setPath(String path) {
Path = path;
}
public int getHataBildirimId() {
return HataBildirimId;
}
public void setHataBildirimId(int hataBildirimId) {
HataBildirimId = hataBildirimId;
}
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public byte[] getResim() {
return Resim;
}
public void setResim(byte[] resim) {
Resim = resim;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(HataBildirimId);
dest.writeByteArray(Resim);
dest.writeByteArray(Thumbnail);
}
public ResimBean(Parcel in) {
readFromParcel(in);
}
public void readFromParcel(Parcel in){
this.HataBildirimId = in.readInt();
this.Resim = new byte[in.readInt()];
this.Thumbnail = new byte[in.readInt()];
}
public static final Parcelable.Creator<ResimBean> CREATOR = new Parcelable.Creator<ResimBean>() {
@Override
public ResimBean createFromParcel(Parcel in) {
return new ResimBean(in);
}
@Override
public ResimBean[] newArray(int size) {
return new ResimBean[size];
}
};
}
EDIT
I changed to rbList = i.getParcelableArrayListExtra("reslist");
but its still crashing.
EDIT 2 Here my logcat error.
04-12 10:27:34.786: E/Surface(9374): getSlotFromBufferLocked: unknown buffer: 0xa5d110d0
EDIT 3 Here how i populate the list
Bitmap bmp = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] thumbArray = stream.toByteArray();
Uri tempUri = getImageUri(getApplicationContext(), bmp);
String picPath = getRealPathFromURI(tempUri);
Bitmap yourSelectedImage = BitmapFactory.decodeFile(picPath);
byte[] bar = getBytesFromBitmap(yourSelectedImage);
ResimBean rb = new ResimBean(Parcel.obtain());
rb.setResim(bar);
rb.setThumbnail(thumbArray);
rb.setPath(picPath);
rbList.add(rb);
Based on Error log added (E/Surface(9374): getSlotFromBufferLocked: unknown buffer: 0xa5d110d0
):
This is a known issue in Marshmallow (6.0). And it has been fixed in 6.0.1