Android Parcelable Implementation with ArrayList<Object>

前端 未结 2 883
名媛妹妹
名媛妹妹 2021-01-18 06:41

so I am implementing a test app in which I will create a Tournament object as Parcelable and will pass them between intents. A tournament include: . A tournament name . Rule

相关标签:
2条回答
  • 2021-01-18 06:48

    here is code that show you how parcle a arraylist

    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];
              }
        }; }
    
    0 讨论(0)
  • 2021-01-18 07:08

    a lot of these things turn out to be R.P.C.'s -- I would write the major portion of the work in traditional Java then try to make the ......

    yep, sure enough:

    Container for a message (data and object references) that can be sent through an IBinder. A Parcel can contain both flattened data that will be unflattened on the other side of the IPC (using the various methods here for writing specific types, or the general Parcelable interface), and references to live IBinder objects that will result in the other side receiving a proxy IBinder connected with the original IBinder in the Parcel.

    in other words Parcel is a form of interprocess communication ....

    you have to re-think the base model as this is not a 10,000 requests a second server - what it is is a hand-held consumer device that can just pull the pointers off the process table if it has to because of where it operates

    I have learned to go to the blog tab at http://android-developers.blogspot.com/?hl=en

    be very careful not to drill the entry deep into stuff that needs to be in worker threads and note the rich synchronization primitives that Java makes easy to use

    Multithreading For Performance

    Posted by Tim Bray on 19 July 2010 at 11:41 AM [This post is by Gilles Debunne, an engineer in the Android group who loves to get multitasked. — Tim Bray]

    it's in the blogs --- much better place to start

    0 讨论(0)
提交回复
热议问题