bundle putParcelable不起作用

时间:2015-02-13 05:05:06

标签: android parcelable

如果我只这样做:

bundle.putParcelable(User.TAG, user);

User user = (User) bundle.getParcelable(User.TAG);

它有效但如果我这样做:

bundle.putString("refer_key", "value");
bundle.putParcelable(User.TAG, user);

bundle.putParcelable(User.TAG, user);

它不起作用。 错误信息:

  

02-13 12:46:13.316:D / Xxx(16704):java.lang.RuntimeException:Parcel android.os.Parcel@42fbdb68:在740偏移量解组未知类型代码6619238   02-13 12:46:13.316:D / Xxx(16704):在android.os.Parcel.readValue(Parcel.java:2038)   02-13 12:46:13.316:D / Xxx(16704):在android.os.Parcel.readMapInternal(Parcel.java:2254)   02-13 12:46:13.316:D / Xxx(16704):在android.os.Bundle.unparcel(Bundle.java:223)   02-13 12:46:13.316:D / Xxx(16704):在android.os.Bundle.get(Bundle.java:282)   02-13 12:46:13.316:D / Xxx(16704):at com.wealoha.social.activity.FragmentWrapperActivity.onCreate(FragmentWrapperActivity.java:37)   02-13 12:46:13.316:D / Xxx(16704):在android.app.Activity.performCreate(Activity.java:5372)   02-13 12:46:13.316:D / Xxx(16704):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)   02-13 12:46:13.316:D / Xxx(16704):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)   02-13 12:46:13.316:D / Xxx(16704):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)   02-13 12:46:13.316:D / Xxx(16704):在android.app.ActivityThread.access $ 700(ActivityThread.java:159)   02-13 12:46:13.316:D / Xxx(16704):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)   02-13 12:46:13.316:D / Xxx(16704):在android.os.Handler.dispatchMessage(Handler.java:99)   02-13 12:46:13.316:D / Xxx(16704):在android.os.Looper.loop(Looper.java:176)   02-13 12:46:13.316:D / Xxx(16704):在android.app.ActivityThread.main(ActivityThread.java:5419)   02-13 12:46:13.316:D / Xxx(16704):at java.lang.reflect.Method.invokeNative(Native Method)   02-13 12:46:13.316:D / Xxx(16704):at java.lang.reflect.Method.invoke(Method.java:525)   02-13 12:46:13.316:D / Xxx(16704):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1209)   02-13 12:46:13.316:D / Xxx(16704):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)   02-13 12:46:13.316:D / Xxx(16704):at dalvik.system.NativeStart.main(Native Method)

User.java:

package com.wealoha.social.beans;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class User implements Parcelable {

    public static final String TAG = User.class.getSimpleName();
    public String id;
    public String type;
    public String name;
    public String birthday; // yyyy-MM-dd
    public String age; // TODO
    public String height; // 1+
    public String weight; // 1+
    public boolean me;
    public String regionCode;
    public String zodiac;
    public String summary;
    public List<String> selfPurposes;
    public String selfTag;
    public Image avatarImage;
    public String avatarImageId;
    // public int distance;
    public long createTimeMillis;
    public boolean profileIncomplete;
    public int alohaCount;
    public int alohaGetCount;
    public boolean aloha;
    public boolean match;
    public int postCount;
    @Deprecated
    public String t;
    public String phoneNum;
    public boolean block;
    public String accessToken;
    public boolean isUpdate;

    public boolean isShowAlohaTimeDialog = false;
    public boolean isShowFeedDialog = false;

    public User() {
    }

    public User(Parcel source) {
        id = source.readString();
        type = source.readString();
        name = source.readString();
        birthday = source.readString();
        age = source.readString();
        height = source.readString();
        weight = source.readString();
        me = source.readByte() != 0;
        regionCode = source.readString();
        zodiac = source.readString();
        summary = source.readString();

        if (selfPurposes == null) {
            selfPurposes = new ArrayList<String>();
        }
        source.readStringList(selfPurposes);
        selfTag = source.readString();
        avatarImage = (Image) source.readParcelable(Image.class.getClassLoader());
        avatarImageId = source.readString();
        createTimeMillis = source.readLong();
        profileIncomplete = source.readByte() != 0;
        alohaCount = source.readInt();
        alohaGetCount = source.readInt();
        aloha = source.readByte() != 0;
        match = source.readByte() != 0;
        postCount = source.readInt();
        t = source.readString();
        phoneNum = source.readString();
        block = source.readByte() != 0;
        accessToken = source.readString();
        isUpdate = source.readByte() != 0;
        isShowAlohaTimeDialog = source.readByte() != 0;
        isShowFeedDialog = source.readByte() != 0;

    }

    public static final Parcelable.Creator<User> CREATOR = new Creator<User>() {

        @Override
        public User createFromParcel(Parcel source) {
            return new User(source);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(type);
        dest.writeString(name);
        dest.writeString(birthday);
        dest.writeString(age);
        dest.writeString(height);
        dest.writeString(weight);
        dest.writeByte((byte) (me ? 1 : 0));
        dest.writeString(regionCode);
        dest.writeString(zodiac);
        dest.writeString(summary);
        dest.writeStringList(selfPurposes);
        dest.writeString(selfTag);
        dest.writeParcelable(avatarImage, flags);
        dest.writeString(avatarImageId);
        dest.writeLong(createTimeMillis);
        dest.writeInt(alohaCount);
        dest.writeInt(alohaGetCount);
        dest.writeByte((byte) (aloha ? 1 : 0));
        dest.writeByte((byte) (match ? 1 : 0));
        dest.writeInt(postCount);
        dest.writeString(t);
        dest.writeString(phoneNum);
        dest.writeByte((byte) (block ? 1 : 0));
        dest.writeString(accessToken);
        dest.writeByte((byte) (isUpdate ? 1 : 0));
        dest.writeByte((byte) (isShowAlohaTimeDialog ? 1 : 0));
        dest.writeByte((byte) (isShowFeedDialog ? 1 : 0));
    }

    public String getId() {
        return id;
    }

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

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

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

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public boolean isMe() {
        return me;
    }

    public void setMe(boolean me) {
        this.me = me;
    }

    public String getRegionCode() {
        return regionCode;
    }

    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    public String getZodiac() {
        return zodiac;
    }

    public void setZodiac(String zodiac) {
        this.zodiac = zodiac;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public List<String> getSelfPurposes() {
        return selfPurposes;
    }

    public void setSelfPurposes(List<String> selfPurposes) {
        this.selfPurposes = selfPurposes;
    }

    public String getSelfTag() {
        return selfTag;
    }

    public void setSelfTag(String selfTag) {
        this.selfTag = selfTag;
    }

    public Image getAvatarImage() {
        return avatarImage;
    }

    public void setAvatarImage(Image avatarImage) {
        this.avatarImage = avatarImage;
    }

    public String getAvatarImageId() {
        return avatarImageId;
    }

    public void setAvatarImageId(String avatarImageId) {
        this.avatarImageId = avatarImageId;
    }

    public long getCreateTimeMillis() {
        return createTimeMillis;
    }

    public void setCreateTimeMillis(long createTimeMillis) {
        this.createTimeMillis = createTimeMillis;
    }

    public boolean isProfileIncomplete() {
        return profileIncomplete;
    }

    public void setProfileIncomplete(boolean profileIncomplete) {
        this.profileIncomplete = profileIncomplete;
    }

    public int getAlohaCount() {
        return alohaCount;
    }

    public void setAlohaCount(int alohaCount) {
        this.alohaCount = alohaCount;
    }

    public int getAlohaGetCount() {
        return alohaGetCount;
    }

    public void setAlohaGetCount(int alohaGetCount) {
        this.alohaGetCount = alohaGetCount;
    }

    public boolean isAloha() {
        return aloha;
    }

    public void setAloha(boolean aloha) {
        this.aloha = aloha;
    }

    public boolean isMatch() {
        return match;
    }

    public void setMatch(boolean match) {
        this.match = match;
    }

    public int getPostCount() {
        return postCount;
    }

    public void setPostCount(int postCount) {
        this.postCount = postCount;
    }

    public String getT() {
        return t;
    }

    public void setT(String t) {
        this.t = t;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public boolean isBlock() {
        return block;
    }

    public void setBlock(boolean block) {
        this.block = block;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public boolean isUpdate() {
        return isUpdate;
    }

    public void setUpdate(boolean isUpdate) {
        this.isUpdate = isUpdate;
    }

    public boolean isShowAlohaTimeDialog() {
        return isShowAlohaTimeDialog;
    }

    public void setShowAlohaTimeDialog(boolean isShowAlohaTimeDialog) {
        this.isShowAlohaTimeDialog = isShowAlohaTimeDialog;
    }

    public boolean isShowFeedDialog() {
        return isShowFeedDialog;
    }

    public void setShowFeedDialog(boolean isShowFeedDialog) {
        this.isShowFeedDialog = isShowFeedDialog;
    }

}

0 个答案:

没有答案