0

i have a class which implement Serializable.

when i'm adding an object from that class to the Intent extra and lunch an activity i have no problems.

but when i'm trying to add the object to an Intent lunched by a PedingIntent in a notificatoin bar, i the get the following error:

08-08 18:20:06.186: E/AndroidRuntime(1332): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object 

this is my code:

        this.tickerText = sender.getName() + " Sent you a new message";
        CharSequence contentTitle = "New message from " + sender.getName();       
        CharSequence contentText = "Click to open";
        Intent chat = new Intent(context, Chat.class);      
        chat.putExtra(app.EXTRA_FACEBOOKUSER, sender);
        chat.putExtra(app.EXTRA_RESET_WAINTING_CHAT_MESSAGES, true);
        PendingIntent intent = PendingIntent.getActivity(context, 0, chat, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);      
        this.setLatestEventInfo(context, contentTitle, contentText, intent);

the sender variable class:

import java.io.Serializable;

import android.graphics.drawable.Drawable;


public class FacebookUser implements Serializable{

    /**
     * 
     */

    private static final long serialVersionUID = 1L;

    private String name, gender, status;    
    private int id;
    private double distance, longitude, latitude;;
    private Drawable profilePicture;
    private boolean isFacebookFriend = false;

    public FacebookUser() {

    }

    public FacebookUser(int id, String name)    {
        this.setId(id);
        this.setName(name);     
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Drawable getProfilePicture() {
        Drawable picture = profilePicture;
        if (picture != null)
            picture = profilePicture.getConstantState().newDrawable();
        return picture;
    }

    public void setProfilePicture(Drawable profilePicture) {
        this.profilePicture = profilePicture;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public boolean isFacebookFriend() {
        return isFacebookFriend;
    }

    public void setFacebookFriend(boolean isFacebookFriend) {
        this.isFacebookFriend = isFacebookFriend;
    }

    public String toString()
    {
        return this.name;
    }

}
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
  • Please provide the `Sender` class. In general, all of its members must either be `Serializable` or `transient`. – Stephan Aug 13 '12 at 17:10

1 Answers1

0

Drawable is not Serializable. Try setting it to transient and to handle the implications of this accordingly in your code. Basically you have to deal with that the Drawable member will be null after de-serialization. You can hook into the serialization process with the readObject and writeObject methods as described in the above link to serialize it yourself.

Stephan
  • 7,360
  • 37
  • 46