RealmObject和Parcelable [英] RealmObject AND Parcelable
问题描述
我是新的领域为Android,所以我不知道我在这个接近的正确途径。我有一个类,它看起来像这样:
I'm new to Realm for Android so I'm not sure I'm approaching this the right way. I have a class which looks like this:
public class Entry extends RealmObject implements Parcelable {
...
}
问题是 Parcelable
接口包含像方法describeContents()
writeToParcel()
和RealmObjects不应该比getter和setter其他方法:
The problem is the Parcelable
interface contains methods like describeContents()
writeToParcel()
and RealmObjects aren't supposed to have methods other than getters and setters:
Error:(81, 17) error: Only getters and setters should be defined in model classes
所以我的问题是:我怎样才能让这两个一起工作?难道还有比创建一个单独的类更好的方法(可能像 RealmEntry
)?这样做会导致大量的重复code的...
So my question is: How can I make these two work together? Is there a better way than creating an separate class (maybe something like RealmEntry
)? Doing so would result in a lot of duplicated code...
推荐答案
这是不可能在目前就RealmObjects实现Parcelable。
一个解决方案是使用两个境界文件:一个默认作为您的对象存储和专业性的临时的轮换等省
It's not possible at the moment to implement Parcelable on RealmObjects. One solution is to Use two realm files: the default one as your object store and a specialized one for temporary saves for rotations etc.
这篇关于RealmObject和Parcelable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!