realm - 将带有包裹的 Realm 对象传递给事件已返回 null

标签 realm parcel

任何人都可以帮助我解决将带有包裹的realmobject传递到另一个事件而在第二个事件中我的对象为空的问题吗?

在事件中,我从标签中获取类类别的实例。

        Intent intent = new Intent(context, CategoryListActivity.class);
        Category category = (Category)v.getTag();
        Log.e("Id", " "+category.getId()); //this is ok it prints 1
        Parcelable parcelable = Parcels.wrap(category);

        intent.putExtra("category", parcelable);
        startActivity(intent); 

在类 CategoryListActivity v 方法 onCreate 中是代码

Intent intent = getIntent();
Category category = Parcels.unwrap(intent.getParcelableExtra("category"));
Category category1= Parcels.unwrap(getIntent().getExtras().getParcelable("category"));
Log.e("Id 1", " "+category.getId()); //retun 0
Log.e("Id 1", " "+category1.getId()); //return 0

这个 print 0 我不知道为什么是 0。任何人都可以提出一些建议来解决这个问题吗?谢谢,或者如果有必要插入扩展 RealmObject 的实体,我可以粘贴

最佳答案

您不应在 Parcel 中发送 RealmObject,除非它们是非托管对象或独立对象。

只发送 ID 值并查询另一端的对象会更安全:https://realm.io/docs/java/latest/#intents

如果您想使用 Parceler。您是否按照此处所述配置了对象:https://realm.io/docs/java/latest/#parceler

关于realm - 将带有包裹的 Realm 对象传递给事件已返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36079592/

相关文章:

ios - 等价查询 MagicalRecord -> Realm.io

swift - 查找 Realm 中包含多个对象的对象

android - 我传递的包裹是空的?

reactjs - React应用程序在本地运行,但部署到Azure Web App时不起作用

Kotlin 中的 Android Parcelable : CREATOR not found on Parcelable data class

reactjs - React 项目中的 URI 格式错误 - 使用 Parcel Bundler

swift - 如何将 Firestore DocumentID 映射到 RealmObject 属性?

ios - 为什么我的 Realm 对象不保存存储值?

swift - 单元格中的图像未出现在搜索结果中

android - com.android.support :appcompat-v7 and design version 23. 2.0 崩溃包裹错误