我正在努力从一个发送我的客户类的对象Activity并在另一个中显示它Activity.
客户类的代码:
public class Customer {
private String firstName, lastName, Address;
int Age;
public Customer(String fname, String lname, int age, String address) {
firstName = fname;
lastName = lname;
Age = age;
Address = address;
}
public String printValues() {
String data = null;
data = "First Name :" + firstName + " Last Name :" + lastName
+ " Age : " + Age + " Address : " + Address;
return data; …Run Code Online (Sandbox Code Playgroud) 我一直在阅读很多文章和文章,颂扬Parcelable在Serializable上的速度.我一直在使用两种方法来通过Intents在Activities之间传递数据,并且在两者之间切换时还没有注意到任何速度差异.我必须传输的典型数据量是5到15个嵌套对象,每个对象有2到5个字段.
由于我有大约30个必须可转移的类,因此实现Parcelable需要大量的样板代码来增加维护时间.我目前的要求之一是编译的代码应该尽可能小; 我希望通过使用Serializable over Parcelable可以节省一些空间.
我应该使用Parcelable还是没有理由在Serializable上使用它来处理这么少量的数据?还是有另一个原因我不应该使用Serializable?
如何将detailHashMap 传递给另一个Activity?
HashMap<String,String> detail = new HashMap<String, String>();
detail.add("name","paresh");
detail.add("surname","mayani");
detail.add("phone","99999");
......
......
Run Code Online (Sandbox Code Playgroud) 我在我的onClick()方法中的代码中有以下内容
List<Question> mQuestionsList = QuestionBank.getQuestions();
Run Code Online (Sandbox Code Playgroud)
现在我有了这一行后的意图,如下:
Intent resultIntent = new Intent(this, ResultActivity.class);
resultIntent.putParcelableArrayListExtra("QuestionsExtra", (ArrayList<? extends Parcelable>) mQuestionsList);
startActivity(resultIntent);
Run Code Online (Sandbox Code Playgroud)
我不知道如何将这个问题列表从一个活动传递到另一个活动My Question类
public class Question {
private int[] operands;
private int[] choices;
private int userAnswerIndex;
public Question(int[] operands, int[] choices) {
this.operands = operands;
this.choices = choices;
this.userAnswerIndex = -1;
}
public int[] getChoices() {
return choices;
}
public void setChoices(int[] choices) {
this.choices = choices;
}
public int[] getOperands() {
return operands;
}
public void setOperands(int[] operands) {
this.operands …Run Code Online (Sandbox Code Playgroud) 假设您要启动一个新活动并从当前活动传递一些数据.如果数据是基本类型,您可以简单地使用intent并添加额外内容,但是如何为更复杂的数据结构(如arraylists或对象)执行此操作?