class Selected_img_layout:
Intent i = new Intent(Selected_img_layout.this, ImagSlider.class);
Bundle bundle = new Bundle();
bundle.putSerializable("image_data", spacecrafts);
i.putExtras(bundle);
startActivity(i);
class ImagSlider:
Bundle bundleobject = getIntent().getExtras();
spacecrafts = (ArrayList<Spacecraft>) bundleobject.getSerializable("image_data");
航天器类:
public class Spacecraft implements Serializable {
Uri uri;
public Spacecraft() {
}
public Spacecraft(String name, Uri uri) {
this.name = name;
this.uri = uri;
}
public Uri getUri() {
return uri;
}
public void setUri(Uri uri) {
this.uri = uri;
}
}
错误
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.letsgo.mypdfconverter.Spacecraft)
替换这个:
public Spacecraft(String name, Uri uri) {
this.name = name;
this.uri = uri;
}
有:
public Spacecraft( Uri uri) {
this.uri = uri;
}
试试这个代码:Intent i = new Intent(Selected_img_layout.this,ImagSlider.class); i.putExtras( “IMAGE_DATA”,宇宙飞船); startActivity(ⅰ);
尝试这样可以将您的数据用于其他活动
宇宙飞船spaceCraft =(Spacecraft)getIntent()。getSerializableExtra(“image_data”)