将对象作为下一个活动的意图

发布于 2024-10-10 17:16:28 字数 151 浏览 0 评论 0原文

是否可以将 Object 类型的对象作为 Extra 放入 Intent 中?我有一个对象类型的变量,直到它被分配一个值时才知道对象数据类型是什么。也许与序列化或捆绑有关,我不确定?然后在下一个活动中,如何获取该值以便将其存储在 ArrayList中?

Is it possible to to put an object of type Object into an intent as a Extra? I have a variable of type object and won't know until it is assigned a value as to what the object datatype is. Maybe something to do with serialization or as a bundle i'm not sure? And then in the next activity how do I then get this value in order to store it in an ArrayList<Object> ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2024-10-17 17:16:28

Bundle 通过 Intent#putExtra 没有任何添加对象的功能。您只能传入 ParcelableSerialized 对象。您想要通过 Intent 传递的任何对象都必须实现这些接口之一。建议实现 Parcelable 这里有一个简短的指南:通过使用 Parcelables 按值参数

此外,这个问题还有更有用的答案:如何使用 Intents 将对象从一个 Android Activity 发送到另一个 Android Activity?

Bundle by way of Intent#putExtra does not have any function to add an Object. You can only pass in a Parcelable or a Serializable object. Any object you want to pass via an Intent must implement one of those interfaces. It's recommended to implement Parcelable there is a brief guide here: Pass by value Parameters using Parcelables.

Also this question has more helpful answers: How to send an object from one Android Activity to another using Intents?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文