我创建了一个对象,其中包含ImageView,boolean和Integer类型的数据字段。
public class MemoryCard implements View.OnClickListener, Serializable {
private ImageView image;
private int id;
private int nr;
private boolean clicked = false;
private int cardBack;
private int cardFront;
public MemoryCard(Context context, int id, int nr, int cardFront)
{
this.id = id;
this.nr = nr;
this.cardBack = R.drawable.backside;
this.cardFront = cardFront;
this.image = new ImageView(context);
this.image.setImageResource(this.cardBack);
this.image.setOnClickListener(this);
}
}
当我开始将对象从MainActivity发送到SecondActivity时,会发生错误,我的应用程序停止运行。
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("object", new MemoryCard(this, 0, 0, R.drawable.myImage));
startActivity(intent);
我认为它与 MemoryCard 构造函数的参数 this 和 R.drawable.myImage 有关,但为什么呢?
答案 0 :(得分:1)
Is ImageView
serializable? An object if serializable only if it implements Serializable
and all its members are serializable.