如何在两个 Activity 之间传递和获取“myobject1”?
第一个 Activity :
private ArrayList<Custom> myobject1 = new ArrayList<Custom>();
...
i.putExtra("myobject1", myobject1);
第二项 Activity :
results =(ArrayList<Custom>) getIntent().getSerializableExtra("myobject1");
这是我的 Custom.class :
public class Custom implements Comparable<Custom>{
private String big;
private String small;
public Custom(String n,String d)
{
big = n;
small = d;
}
public String getFirst()
{
return big;
}
public String getSecond()
{
return small;
}
@Override
public int compareTo(Custom o) {
if(this.big != null)
return this.big.toLowerCase().compareTo(o.getFirst().toLowerCase());
else
throw new IllegalArgumentException();
}
}
此时我收到错误: E/AndroidRuntime(8032): java.lang.RuntimeException: Parcel: 无法编码(marshal)值
最佳答案
为了将值从一个 Activity
传递到另一个,您尝试传递的对象的 Class
应该实现 Parcelable
接口(interface)。您可以在这里找到更多信息http://developer.android.com/reference/android/os/Parcelable.html 。如果您需要更具体的内容,请拍摄!
关于java - Android Intent - 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8551525/