任何人都可以帮助我解决将带有包裹的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/