Android:如何在活动之间传递ArrayList ?(Android: How to pass ArrayList between Activities?)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
Android:如何在活动之间传递ArrayList ?(Android: How to pass ArrayList between Activities?)

我如何将Object:ArrayList从一个Activity传递到另一个?

似乎意图不能容纳除ArrayList外的自定义内容。

作为一种破解,我使用了一个静态成员:

staticResultList = new ArrayList<SingleExamResult>(m_examResults);

并通过以下方式获取以下活动:

m_examResults = DoExam.staticResultList;

这显然不是正确的方式,任何“常见”方法? 非常感谢!

How can I pass a Object: ArrayList from one Activity to another?

Seems that intent cannot hold custom ones except ArrayList.

As a kind of hack, I use a static member:

staticResultList = new ArrayList<SingleExamResult>(m_examResults);

and Get it in the following Activity by:

m_examResults = DoExam.staticResultList;

It's not the correct way obviously, any 'common' approaches? Thanks a lot!

最满意答案

如果你想避免使用静态成员破解,你的自定义类SingleExamResult必须实现Parcelable接口:

http://developer.android.com/reference/android/os/Parcelable.html

If you want to avoid using the static member hack, your custom class, SingleExamResult, must implement the Parcelable interface:

http://developer.android.com/reference/android/os/Parcelable.html

更多推荐

本文发布于:2023-04-12 21:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/6f631d253044a0ef86708c6d3b5fc609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Android   ArrayList   Activities   pass

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!