android:将可序列化对象放入意图的问题 [英] android: problem with Serializable object put into intent
本文介绍了android:将可序列化对象放入意图的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类的问题,我想通过将它放入 putExtras() 来传递一个意图它是可序列化的,代码如下所示:
Hi i have problem with a class i want to pass in an intent by putting it into the putExtras() Its serializable and the code looks like this:
public abstract class ObjectA extends ArrayList<ObjectA> implements java.io.Serializable{...}
public class ObjectB extends ObjectA {...}
...
Bundle extras = new Bundle();
extras.putSerializable("blabla", ObjectB);
intent.putExtras(extras);
...
Object y = getIntent().getExtras().get("blabla");
问题是,y 现在是一个 ArrayList 而不再是 ObjectB,所以我不能投射它..如果我将代码更改为
the problem is, that y now is an ArrayList and no longer an ObjectB so i cant cast it.. if i change the code to
public class ObjectB implements java.io.Serializable {...}
效果很好
推荐答案
通过在您的类中实现 java.util.List 和 java.io.Serializable,您触发了这个 android 错误.
By implementing both java.util.List and java.io.Serializable in your class you've triggered this android bug.
这篇关于android:将可序列化对象放入意图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文