Android:使用可包裹对象恢复数据

Android:使用可包裹对象恢复数据,android,object,parcelable,Android,Object,Parcelable,-问题已解决- 我想将Activity1中存在的对象发送到Activity2。要做到这一点,我使用的是Parcelable 我有一个实现Parcelable的类用户 在我的第一个活动中,我创建了一个用于测试的用户,如下所示: User userTest = new User("Name", "FirstName", "AdressTest", 1, "99999", "Nice guy", "pic.jpg",null); 我称下一个活动为: Intent i

-问题已解决-

我想将Activity1中存在的对象发送到Activity2。要做到这一点,我使用的是Parcelable

我有一个实现Parcelable的类用户

在我的第一个活动中,我创建了一个用于测试的用户,如下所示:

            User userTest = new User("Name", "FirstName", "AdressTest", 1, "99999", "Nice guy", "pic.jpg",null);
我称下一个活动为:

     Intent intent = new Intent(
        MainActivity.this,
        UserProfile.class
    );
    intent.putExtra("userParce", userTest);
    startActivity(intent);
问题是,当我想在Activity2中显示此用户的数据时,我会这样做:

   Intent intent = getIntent();
   User user_current = intent.getExtras().getParcelable("userParce");
   Log.i("User Name", user_current.getName());
   Log.i("User FirstName", user_current.getFirstName());
   Log.i("User Adress", user_current.getAdress());
   etc...
问题是只有名字和名字在显示,其他的都是空的,我不明白为什么:'

有人帮我吗

附言:

我没有显示所有的代码,因为它是无用的,因此,只有一个构造函数和我的getter

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

    @Override
public void writeToParcel(Parcel dest, int flags)
{
    dest.writeString(name);
    dest.writeString(firstName);
    dest.writeString(adress);
    dest.writeInt(numberTest);
    dest.writeString(code);
    dest.writeString(description);
    dest.writeString(image);
    dest.writeList(listObject);
}

        public static final Parcelable.Creator<User> CREATOR = new      Parcelable.Creator<User>()
{
    @Override
    public UsercreateFromParcel(Parcel source)
    {
        return new User(source);
    }

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

    public static Parcelable.Creator<User> getCreator()
{
    return CREATOR;
}

    public User(Parcel in) {
    this.name= in.readString();
    this.firstName= in.readString();
    this.numberTest= in.readInt();
    this.code = in.readString();
    this.description = in.readString();
    this.image = in.readString();
    this.listObject = null;
}

向我们展示您的Parcelable实现我编辑了我的帖子,thx:OMG,我发现了问题,非常愚蠢x我在公共UserParcel中忘记了一行…..您的类称为User,但您的Parcelable实现构造函数是Snack。你现在已经改变了。。