在还原实例上创建包裹时出错 Android

Error to create parcel on restore instance Android

我在 Android 中尝试恢复我的单例对象中的实例时遇到问题。 我有原始变量和对象列表。

这是我的对象:

 String idUsuario, email, idDevice, nombreUsuario, currency;
        List<ObjectExample> list;
        long fechaCreacion;
        double valorUnidad;
        int premium;

我的包裹实施是:

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(idUsuario);
    dest.writeString(email);
    dest.writeString(idDevice);
    dest.writeString(nombreUsuario);
    dest.writeString(currency);
    dest.writeLong(fechaCreacion);
    dest.writeDouble(valorUnidad);
    dest.writeInt(premium);
    dest.writeList(list);
}


protected User_Singleton(Parcel in) {
    idUsuario = in.readString();
    email = in.readString();
    idDevice = in.readString();
    nombreUsuario = in.readString();
    currency = in.readString();
    fechaCreacion = in.readLong();
    valorUnidad = in.readDouble();
    premium = in.readInt();
    list = new ArrayList<ObjectExample>();
    in.readList(list, ObjectExample.class.getClassLoader());
}

public static final Creator<User_Singleton> CREATOR = new Creator<User_Singleton>() {
    @Override
    public User_Singleton createFromParcel(Parcel in) {
        return new User_Singleton();
    }

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

我的对象示例:

int monthNumber, yearNumber;
double bank;

public ObjectExample() {
}

public ObjectExample(int monthNumber, int yearNumber, double bank) {
    this.monthNumber = monthNumber;
    this.yearNumber = yearNumber;
    this.bank = bank;
}

protected ObjectExample(Parcel in) {
    monthNumber = in.readInt();
    yearNumber = in.readInt();
    bank = in.readDouble();
}

public static final Creator<ObjectExample> CREATOR = new Creator<ObjectExample>() {
    @Override
    public ObjectExample createFromParcel(Parcel in) {
        return new ObjectExample(in);
    }

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

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(monthNumber);
    dest.writeInt(yearNumber);
    dest.writeDouble(bank);
}

我得到了这个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{example.Principal.MainActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@e7eb28e: Unmarshalling unknown type code 6619252 at offset 4036
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2836)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2911)
 at android.app.ActivityThread.-wrap11(Unknown Source:0)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1608)
 at android.os.Handler.dispatchMessage(Handler.java:105)
 at android.os.Looper.loop(Looper.java:164)
 at android.app.ActivityThread.main(ActivityThread.java:6665)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@e7eb28e: Unmarshalling unknown type code 6619252 at offset 4036
 at android.os.Parcel.readValue(Parcel.java:2754)
 at android.os.Parcel.readArrayMapInternal(Parcel.java:3042)
 at android.os.BaseBundle.unparcel(BaseBundle.java:257)
 at android.os.BaseBundle.getBoolean(BaseBundle.java:834)
 at android.app.Activity.restoreHasCurrentPermissionRequest(Activity.java:7305)
 at android.app.Activity.performCreate(Activity.java:7056)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2789)
 ... 9 more

phone 重新启动时,会出现该错误。 我认为是列表,但问题是什么?

非常感谢。

在你的 User_Singletone 中传递参数 (Parcel in) in constrictor

public static final Creator<User_Singleton> CREATOR = new Creator<User_Singleton>() {
    @Override
    public User_Singleton createFromParcel(Parcel in) {
        //return new User_Singleton();
        return new User_Singleton(in);
    }

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