简体   繁体   English

Android:将可序列化的对象数据传递给另一个活动

[英]Android: Pass serialisable object data to another activity

I have a class, which contains an array list of another object, when I try to pass the data to another activity, it does not pass other objects like my array list Appointment, how to do? 我有一个类,其中包含另一个对象的数组列表,当我尝试将数据传递给另一个活动时,它没有传递其他对象,例如我的数组列表约会,该怎么办? Here are my classes: 这是我的课程:

open class Customer(var name: String = "") : Serializable{
    var appointments: List<Appointment>? = null
}

And: 和:

class Appointment(val id: String?, val title: String?, val date: Date) : Serializable { 
}

To pass data: 传递数据:

putExtra("customer", customer)

To get data: 要获取数据:

intent.getSerializableExtra("customer") as Customer?

It works, but the list of appointments is not sent, only the customer, why? 它有效,但是约会列表没有发送,只有客户发送,为什么?

The list is not null before doing the startActivity, but when I do the getIntent I get the null list, it was not sent 在执行startActivity之前,该列表不为null,但是当我执行getIntent时,我获得了null列表,但未发送该列表

List doesn't implement Serializable . List未实现Serializable

How about try to use Arraylist . 如何尝试使用Arraylist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM