0
votes

Here is my declaration

List lstProfilePicture = new ArrayList();

This is my code for calling another activity

Intent i = new Intent(LogoActivity.this, MenuActivity.class);

i.putExtra("Profile", (Serializable) lstProfilePicture);

This is my Profile Class

public class Profile implements Serializable {

private Long employeeCode;
private Bitmap employeePicture;

public Profile() {
}

public Profile(Long employeeCode, Bitmap employeePicture) {
    this.employeeCode = employeeCode;
    this.employeePicture = employeePicture;
}

public Long getEmployeeCode() {
    return employeeCode;
}
public void setEmployeeCode(Long employeeCode) {
    this.employeeCode = employeeCode;
}
public Bitmap getEmployeePicture() {
    return employeePicture;
}
public void setEmployeePicture(Bitmap employeePicture) {
    this.employeePicture = employeePicture;
}

}

Here is my error message

/AndroidRuntime: FATAL EXCEPTION: main Process: oras.liv.com.oras, PID: 21484 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object

How to I pass with a bitmap in class? Is there another way?

1

1 Answers

-1
votes

Convert it to a Byte array

Activity 1:

try {
    //Write file
    String filename = "bitmap.png";
    FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE);
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

    //Cleanup
    stream.close();
    bmp.recycle();

    //Pop intent
    Intent in1 = new Intent(this, Activity2.class);
    in1.putExtra("image", filename);
    startActivity(in1);
} catch (Exception e) {
    e.printStackTrace();
}

In Activity 2, load up the bitmap:

Bitmap bmp = null;
String filename = getIntent().getStringExtra("image");
try {
    FileInputStream is = this.openFileInput(filename);
    bmp = BitmapFactory.decodeStream(is);
    is.close();
} catch (Exception e) {
    e.printStackTrace();
}