Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how you can pass an ArrayList as I tried it.</p> <p><strong>MyListClass.java - Custom class</strong></p> <pre><code>public class MyListClass implements Parcelable{ private int test; public MyListClass() {} public MyListClass(Parcel read){ test = read.readInt(); } public int getTest() { return test; } public void setTest(int test) { this.test = test; } public static final Parcelable.Creator&lt;MyListClass&gt; CREATOR = new Parcelable.Creator&lt;MyListClass&gt;() { @Override public MyListClass createFromParcel(Parcel source) { return new MyListClass(source); } @Override public MyListClass[] newArray(int size) { return new MyListClass[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel arg0, int arg1) { arg0.writeInt(test); } } </code></pre> <p><strong>MyParcelable.java</strong></p> <pre><code>public class MyParcelable implements Parcelable { private List&lt;MyListClass&gt; arrList = new ArrayList&lt;MyListClass&gt;(); private int myInt = 0; private String str = null; public String getStr() { return str; } public void setStr(String str) { this.str = str; } public List&lt;MyListClass&gt; getArrList() { return arrList; } public void setArrList(List&lt;MyListClass&gt; arrList) { this.arrList = arrList; } public int getMyInt() { return myInt; } public void setMyInt(int myInt) { this.myInt = myInt; } MyParcelable() { // initialization arrList = new ArrayList&lt;MyListClass&gt;(); } public MyParcelable(Parcel in) { myInt = in.readInt(); str = in.readString(); in.readTypedList(arrList, MyListClass.CREATOR); } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel outParcel, int flags) { outParcel.writeInt(myInt); outParcel.writeString(str); outParcel.writeTypedList(arrList); } public static final Parcelable.Creator&lt;MyParcelable&gt; CREATOR = new Parcelable.Creator&lt;MyParcelable&gt;() { @Override public MyParcelable createFromParcel(Parcel in) { return new MyParcelable(in); } @Override public MyParcelable[] newArray(int size) { return new MyParcelable[size]; } }; } </code></pre> <p><strong>MainAcitivty.java</strong> </p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); arrList.add(new MyListClass()); arrList.get(0).setTest(200); MyParcelable object = new MyParcelable(); object.setMyInt(100); object.setArrList(arrList); Intent intent = new Intent(MainActivity.this,ReceiverParcel.class); intent.putExtra("parcel", object); startActivity(intent); } </code></pre> <p><strong>ReceiverParcel.java</strong></p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle b = getIntent().getExtras(); MyParcelable object = b.getParcelable("parcel"); System.out.println(object.getArrList().get(0).getTest()); System.out.println(object.getMyInt()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload