我试图用bundle传递realm对象,我使用Parcel库
这是我的领域模型类。 Album.java
@Parcel
public class Album extends RealmObject implements Serializable {
@PrimaryKey
public String id;
public String upc;
public String albumName;
public String albumArtUrl;
public String artistName;
public String genre_id;
public String genreName;
public String price;
public String releaseYear;
public int explicit;
public RealmList<Song> songs = new RealmList<>();
}
这是Song.java。
@Parcel
public class Song extends RealmObject implements Serializable {
@PrimaryKey
public String id;
public String isrc;
public String songName;
public String artistName;
public String album_id;
public String albumArtUrl;
public String genre_id;
public String genreName;
public String releaseYear;
public String price;
public String lyrics;
public String demo;
public int explicit;
}
当我尝试像这样传递相册对象时,
b.putParcelable("album", Parcels.wrap(album));
我有这个错误。
Unable to find generated Parcelable class for com.devhousemyanmar.juketrill.models.Album, verify that your class is configured properly and that the Parcelable class com.devhousemyanmar.juketrill.models.Album$$Parcelable is generated by Parceler.
请帮我解决这个问题。
如果您查看文档,它有一个专门用于using Parceler的部分。
// All classes that extend RealmObject will have a matching RealmProxy class created
// by the annotation processor. Parceler must be made aware of this class. Note that
// the class is not available until the project has been compiled at least once.
@Parcel(implementations = { PersonRealmProxy.class },
value = Parcel.Serialization.BEAN, // <-- requires getters/setters if set
analyze = { Person.class })
public class Person extends RealmObject {
// ...
}
但值得注意的是,如果在将implementations = {PersonRealmProxy.class}
传递给realm.copyFromRealm(song)
之前使用Parcels.wrap()
,则不需要指定bean
。无论如何,如果你想使用字段值而不是a RealmList parceler configuration序列化策略,你还是需要这样做。
此外,您可能需要qazxswpoi。