parceler的使用(@Parcel)与Realm.io(安卓) [英] Usage of parceler (@Parcel) with Realm.io (Android)

查看:857
本文介绍了parceler的使用(@Parcel)与Realm.io(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code产生错误:错误:Parceler:找不到读取类型io.realm.Realm的io.realm.RealmObject.realm

这是工作一切正常没有扩展RealmObject ,但是我想用领域将数据库轻松。有没有一种方法来exlcude的RealmObject领域,只使用基本的POJO字段@Parcel?

  @Parcel
公共类饲料扩展RealmObject {
    INT ID;
    公共字符串文本;
    公共字符串time_created;
    字符串time_modified;
    INT comments_count;
    INT likes_count;
    字符串feed_type;
    INT obj_id;
    字符串图像;
    字符串用户名;
    字符串user_earthmile_points;
    布尔喜欢;
    布尔评论;
    布尔is_private;
    字符串URL;
    INT feed_creator_id;

   }
 

解决方案

编辑#2 :其实,我找到了一种方法,使其工作:)。请参阅下面的更新的答案。

编辑#1 :当应用程序编译就好了,它试图以实际创建一个时崩溃包裹,出现错误: org.parceler.ParcelerRuntimeException:无法创建ParcelableFactory为io.realm.FeedRealmProxy 。境界队正式承认,这是目前无法实施 Parcelable RealmObject 秒。目前还不清楚,如果/当此将得到解决。


使用 Parceler v0.2.16 ,你可以这样做:

@RealmClass //如果需要使用JDK 1.6(无关Parceler问题) @Parcel(值= Parcel.Serialization.BEAN,分析= {Feed.class}) 公共类饲料扩展RealmObject {     // ... }

然后,使用 Parcels.wrap(Feed.class,饲料)而不是 Parcels.wrap(饲料)无处不在,否则你的应用程序将与 org.parceler.ParcelerRuntimeException崩溃:无法创建ParcelableFactory为io.realm.FeedRealmProxy

I have the following code which produces the error: Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm

It was working all fine without extends RealmObject , however I want to use Realm to put to database easily. Is there a way to exlcude the RealmObject fields and just use the basic pojo fields for @Parcel?

@Parcel
public class Feed extends RealmObject{
    int id;
    public String text;
    public String time_created;
    String time_modified;
    int comments_count;
    int likes_count;
    String feed_type;
    int obj_id;
    String image;
    String user_name;
    String user_earthmile_points;
    boolean liked;
    boolean commented;
    boolean is_private;
    String url;
    int feed_creator_id;

   }

解决方案

EDIT #2: Actually, I found a way to make it work :). See the updated answer below.

EDIT #1: While the app compiles just fine, it crashes when trying to actually create a Parcel with the error: org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy. The Realm team has officially acknowledged that it is currently not possible to implement Parcelable on RealmObjects. It is unclear if / when this will be resolved.


With Parceler v0.2.16, you can do this:

@RealmClass      // required if using JDK 1.6 (unrelated to Parceler issue)
@Parcel(value = Parcel.Serialization.BEAN, analyze = { Feed.class })
public class Feed extends RealmObject {
    // ...
}

Then, use Parcels.wrap(Feed.class, feed) instead of Parcels.wrap(feed) everywhere, otherwise your app will crash with org.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.FeedRealmProxy.

这篇关于parceler的使用(@Parcel)与Realm.io(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆