【问题标题】:Android Bundle doesn't recognize serializable object as serializedAndroid Bundle 无法将可序列化对象识别为已序列化
【发布时间】: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


【解决方案1】:

找到了我自己的答案,而且很简单。

我需要做的就是将额外的内容作为热身:

Warmup 预热 = (Warmup) extras.getSerializable(Warmup.class.getSimpleName());

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多