我正在利用以下类,我将其作为对象:http://pastebin.com/rKmtbDgF http://pastebin.com/rKmtbDgF
我正在尝试使用以下方式传递它:
Intent booklist = new Intent(getBaseContext(), BookList.class);
Bundle bundle = new Bundle();
bundle.putParcelable("imageManager", (Parcelable) im);
booklist.putExtras(bundle);
booklist.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(booklist);
我正在尝试使用以下方式接收它:
ImageManager im = (ImageManager) getIntent().getExtras().getParcelable("imageManager");
我收到以下错误:
java.lang.ClassCastException: com.example.example.ImageManager
最简单的方法是实现 Serialized ..
import java.io.Serializable;
@SuppressWarnings("serial")
public class Student implements Serializable {
public Student(int age, String name){
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
private int age;
private String name;
}
将对象从活动 A 发送到活动 B
Student student = new Student (18,"Zar E Ahmer");
Intent i = new Intent(this, B.class);
i.putExtra("studentObject", student);
startActivity(i);
在 Activity B 中获取对象。
Intent i = getIntent();
Student student = (Student)i.getSerializableExtra("studentObject");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)