gpt4 book ai didi

android - 在由其他对象组成的类中实现 Parcelable 接口(interface)

转载 作者:行者123 更新时间:2023-11-29 02:09:09 25 4
gpt4 key购买 nike

我有以下代码在我的应用程序中创建一个基本配置文件,它包含另一个类的对象,该类将所有用户的性能数据保存在数组和各种其他原始数据类型中。我将如何在此类中实现 parcelable 接口(interface),以便我可以将用户配置文件对象传递到我的应用程序中的各种 Activity 以进行读取或写入?我是否必须在 Performance 类和这个 Profile 类中实现 parcelable 接口(interface)?

public class Profile {

private String name;
private String email;
private Performance Progress;

private int seed;
private int LastRevisionQuestion = 0;

private int[] LastQuestionQuizLinear = {0,0,0};
private int[] tempScoreQuizLinear = {0,0,0};

private int[] LastQuestionQuizRandom = {0,0,0};
private int[] tempScoreQuizRandom = {0,0,0};

private int[] LastQuestionTimedQuizLinear = {0,0,0};
private int[] tempScoreTimedQuizLinear = {0,0,0};
private int[] tempTotalTimeTimedQuizLinear = {0,0,0};

private int[] LastQuestionTimedQuizRandom = {0,0,0};
private int[] tempScoreTimedQuizRandom = {0,0,0};
private int[] tempTotalTimeTimedQuizRandom = {0,0,0};


/**
* Default constructor
*/
public Profile(){
this("ProfileName", "ProfileEmail");
}

/**
* Overloaded constructor takes user name and email address as input parameter to create a new user
* @param name
* @param email
*/
public Profile(String name, String email){
this.name = name;
this.email = email;
setProgress(new Performance());
}
}

最佳答案

您只能打包简单数据类型(int、String、boolean 等)、parcelablesmap。所以,是的,您最好的选择是在 Performance 中实现 parcelable

关于android - 在由其他对象组成的类中实现 Parcelable 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8438535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com