我想在调用下一个活动(Activity2)之前存储一个在Activity(比如Activity1)中收到的包,并在我回到同一个Activity(到Activity1)时检索同一个包。我该怎么做?
答案 0 :(得分:0)
试试这个,
public class ParcleListTopic implements Parcelable{
private List<ParcleTopic> list;
private ArrayList<HoldListTopic> listh=new ArrayList<HoldListTopic>();
public ArrayList<HoldListTopic> GetListTopic()
{
for(int i=0;i<list.size();i++)
{
listh.add(list.get(i).GetHold());
}
return listh;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(list);
}
public ParcleListTopic(Parcel in)
{
in.readTypedList(list,ParcleTopic.CREATOR);
}
public ParcleListTopic(List<ParcleTopic> list)
{
this.list=list;
}
public static final Parcelable.Creator<ParcleListTopic> CREATOR = new Parcelable.Creator<ParcleListTopic>(){
public ParcleListTopic createFromParcel(Parcel s)
{
return new ParcleListTopic(s);
}
public ParcleListTopic[] newArray(int size)
{
return new ParcleListTopic[size];
}
};
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
}
public class ParcleTopic implements Parcelable
{
HoldListTopic hold;
public ParcleTopic(HoldListTopic hold)
{
this.hold=hold;
}
public HoldListTopic GetHold()
{
return hold;
}
public int describeContents()
{
return 0;
}
public void writeToParcel(Parcel dest, int flags)
{
dest.writeString(hold.Title);
dest.writeString(hold.Date);
dest.writeInt(hold.NumberComment);
dest.writeInt(hold.ID);
}
public ParcleTopic(Parcel in)
{
hold.Title=in.readString();
hold.Date=in.readString();
hold.NumberComment=in.readInt();
hold.ID=in.readInt();
}
public static final Parcelable.Creator<ParcleTopic> CREATOR = new Parcelable.Creator<ParcleTopic>()
{
public ParcleTopic createFromParcel(Parcel s)
{
return new ParcleTopic(s);
}
public ParcleTopic[] newArray(int size)
{
return new ParcleTopic[size];
}
}; }