0

Serializableを実装するクラスがあります。

そのクラスのオブジェクトをインテントエクストラに追加してアクティビティをランチするときは、問題はありません。

しかし、notificatoinバーのPedingIntentによってランチされたインテントにオブジェクトを追加しようとすると、次のエラーが発生します。

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

これは私のコードです:

        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);

送信者変数クラス:

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;
    }

}
4

1 に答える 1

0

DrawableではありませんSerializable。に設定して、コードでこれの意味transientを適切に処理してみてください。基本的に、逆シリアル化後にメンバーが null になることに対処する必要があります。上記のリンクで説明されているように、およびメソッドを使用してシリアル化プロセスにフックし、自分でシリアル化することができます。DrawablereadObjectwriteObject

于 2012-08-13T17:18:25.600 に答える