title: How to pass ArrayList of object between activities using Parcelable?
body: <p>I want to send array list of object from one activity to another. For this I have extended my class with Parcelable. </p>
  
  <p>Still I am not getting the list. Also I have sent a boolean variable for that also value dose not get change.</p>
  
  <p>My object class:</p>
  
  <pre><code>public class contact implements Parcelable {
  
  private String contactName;
  private String contactId;
  
  contact(){}
  
  contact(String contactId,String contactName)
  {
      this.contactId = contactId;
      this.contactName = contactName;
  
  }
  
  public contact(Parcel in) {
  
      contactId  = in.readString();
      contactName = in.readString();
  
  }
  public void writeToParcel(Parcel dest, int flags) {
  
      dest.writeString(contactId);
      dest.writeString(contactName);
  
  }
  
  public static final Parcelable.Creator&lt;contact&gt; CREATOR = new Parcelable.Creator&lt;contact&gt;()
  {
      public contact createFromParcel(Parcel in)
      {
          return new contact(in);
      }
      public contact[] newArray(int size)
      {
          return new contact[size];
      }
  };
  
  public int describeContents() {
      // TODO Auto-generated method stub
      return 0;
  }
  
  public String getContactName() {
      return contactName;
  }
  
  public void setContactName(String contactName) {
      this.contactName = contactName;
  }
  
  public String getContactid() {
      return contactId;
  }
  
  public void setContactid(String contactId) {
      this.contactId = contactId;
  }
  
  }
  </code></pre>
  
  <p>First activity :</p>
  
  <pre><code>   done.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
  
  
              Log.d("selectd",String.valueOf(selectedItemsPositions));
  
              mContactListActivity = true;
  
              selectedContacts = new ArrayList&lt;&gt;();//to store selected items
  
              for (Integer pos : selectedItemsPositions) {
                  selectedContacts.add(items.get(pos));
              }
  
              Intent i = new Intent();
  
              Bundle bundle = new Bundle();
  
              bundle.putParcelableArrayList("selectedContacts",selectedContacts);
              bundle.putBoolean("contactListActivity",mContactListActivity);
  
              i.putExtras(bundle);
  
              setResult(RESULT_OK, i);
  
             finish();
  
  
          }
      });
  
  }
  </code></pre>
  
  <p>Second Activity :</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // Check which request we're responding to
      if (requestCode == PICK_CONTACT_REQUEST) {
          // Make sure the request was successful
          if (resultCode == RESULT_OK) {
  
              Intent i = new Intent();
  
              Bundle bundle = new Bundle();
  
              mSelectedContacts = bundle.getParcelableArrayList("selectedContacts");
  
              mContactListActivity = bundle.getBoolean("contactListActivity");
  
              if(mContactListActivity)
              {
  
                  addOrganizer.setVisibility(View.INVISIBLE);
  
              }
  
              mAdapter.notifyDataSetChanged();
  
          }
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>tried this as suggested by sush :</p>
  
  <pre><code>   Intent i = getIntent();
  
              Bundle bundle = i.getExtras();
  
              mSelectedContacts = (ArrayList&lt;contact&gt;)bundle.getSerializable("selectedContacts");
  
              mContactListActivity = bundle.getBoolean("contactListActivity",false);
  </code></pre>
  
  <p>It then throws null pointer exception on list.</p>
  
  <p>What's going wrong?</p>
  
  <p>UPDATE :</p>
  
  <pre><code>     mContactListActivity = true;
  
              selectedContacts = new ArrayList&lt;&gt;();//to store selected items
  
              for (Integer pos : selectedItemsPositions) {
                  selectedContacts.add(items.get(pos));
              }
  
              Intent i = new Intent(ContactList.this,PlanEventActivity.class);
  
              i.putExtra("contactListActivity",mContactListActivity);
              i.putExtra("selectedContacts",(Serializable)selectedContacts);
  
              setResult(RESULT_OK, i);
  
             finish();
  </code></pre>
  
  <p>Second activity:</p>
  
  <pre><code>   Intent i = getIntent();
  
  
              mContactListActivity =  i.getBooleanExtra("contactListActivity",true);
  </code></pre>
  
  <p>mSelectedContacts = (ArrayList)i.getSerializableExtra("selectedContacts");</p>
  
  <pre><code>            Log.e("mSelectedContact ", String.valueOf(mSelectedContacts));
              mAdapter.notifyDataSetChanged();
  </code></pre>
  
  <p>Now I have done this , now boolean is getting pass but the list shows null.</p>