【发布时间】:2019-05-06 11:26:18
【问题描述】:
我正在尝试在包中传递一个可序列化的对象。
尝试在另一个 Activity 中检索对象时,出现错误:
“不兼容的类型:
必需:com.xxxxxx.Warmup(我的可序列化对象 - xxx 填充 包名)
找到:java.io.Serializable"
将对象放入包中的代码:
// Display the Exercise Category List by
// starting the ExerciseCategoryMainActivity
Intent intent;
intent = new Intent(getContext(), ExerciseCategoryMainActivity.class);
intent.putExtra(Warmup.class.getSimpleName(), warmup);
startActivity(intent);
我尝试检索对象的代码(并得到错误消息不兼容的类型):
// Get the attached bundle from the intent
Bundle extras = getIntent().getExtras();
Warmup warmup = extras.getSerializable(Warmup.class.getSimpleName());
显示我的对象是可序列化的代码:
public class Warmup implements Serializable {
public static final long serialVersionUID = 20180228L;
【问题讨论】:
-
我自己想出了这个,解决方案非常简单。只需要将附加内容作为热身:
标签: android android-intent bundle serializable