如何通过意图之间的物体 [英] how to pass objects between intents

查看:128
本文介绍了如何通过意图之间的物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据我想意图之间传递的一类,这个类有ArrayList中包含另一个类的对象。这是我班

I have a class that contains data i want to pass it between intents, this class have arraylist that contains another class objects. this is my class

    public class ParsedData implements Parcelable {

        public String error;
        public float protectionLevel;
        public int protectionLevelColor;
        public double lastBackup;
        public boolean compressedType;
        public Long driveFreeSpaceSize;
        ArrayList<Item>Items = new ArrayList<Item>();
}

class Item {

    public String name;
    public float percentage;
    public int files;
    public long size;
}

我怎么能发送意图之间的类?

how can i send this class between intents ?

推荐答案

这可能是你的问题:

类实现Parcelable接口还必须有一个静态字段名为 CREATOR ,这是实现一个目标的 Parcelable.Creator 接口。

Classes implementing the Parcelable interface must also have a static field called CREATOR, which is an object implementing the Parcelable.Creator interface.

另外,我想尝试有项目实施 Parcelable ,以及

Alternatively, I'd try to have Item implement Parcelable, as well.

故障安全的替代方法是写你的数据结构成JSON字符串,这也可以让你通过数据没有访问您的 ParsedData 类。

The fail-safe alternative is to write your data structure into a JSON string, which also allows you to pass the data to other applications that don't have access to your ParsedData class.

这篇关于如何通过意图之间的物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆