title: Android studio. Parceling data to a specific object in an array list
body: <pre><code>package com.example.hussain.assignment4task1;
  
  import android.os.Parcel;
  import android.os.Parcelable;
  
  import java.lang.reflect.Array;
  import java.util.ArrayList;
  
  public class Image implements Parcelable
  {
      private String imageName;
      private String date;
      public ArrayList&lt;Image&gt; images;
  
  
  public Image(String imageName, String date, ArrayList&lt;Image&gt; images)
  {
      update(imageName, date, images);
  }
  
  public void update(String imageName, String date, ArrayList&lt;Image&gt; images)
  {
      this.imageName = imageName;
      this.date = date;
      this.images = images;
  }
  
  public String toString()
  {
      String str = "Image Name: "+ imageName;
      str += "\nDate: " + date;
      return str;
  }
  
  /** The following block of code parcels / unparcels data for distribution between activities */
  
  /** Describe the contents in the parcel --
   * interface forces implementation */
  public int describeContents()
  {
      return 0;
  }
  
  public void writeToParcel(Parcel out, int flags)
  {
      out.writeString(imageName);
      out.writeString(date);
      out.writeList(images);
  }
  
  public static final Parcelable.Creator&lt;Image&gt; CREATOR =
          new Parcelable.Creator&lt;Image&gt;()
          {
              public Image createFromParcel(Parcel in)
              {
                  return new Image(in);
              }
  
              public Image[] newArray(int size)
              {
                  return new Image[size];
              }
          };
  /** Private constructor called internally only */
  private Image(Parcel in)
  {
      imageName = in.readString();
      date = in.readString();
  }
  }
  </code></pre>
  
  <p><strong>This is my activity where i insert the image details to be passed to the image in the other activity.</strong></p>
  
  <pre><code>public void onBackPressed()
  {
      Log.i("IMAGE DETAILS", "Back Button Pressed");
      storeImageDetails(); // to cover half filled forms
      Intent resultIntent = new Intent(this, MainActivity.class);
      // need an array list even if we put a single object only
      ArrayList&lt;Image&gt; dataList = new ArrayList&lt;Image&gt;(4);
      dataList.add(image);
      resultIntent.putParcelableArrayListExtra("IMAGE_DATA", dataList);
      setResult(RESULT_OK, resultIntent);
      ImageDetailsActivity.super.onBackPressed();  // do not forget
  }
  
  /** This method will store all information entered */ 
  private void storeImageDetails()
  {
      EditText imageNameText = (EditText) findViewById(R.id.imageNameText);
      EditText dateText = (EditText) findViewById(R.id.dateText);
      String imageName = imageNameText.getText().toString();
      String date = dateText.getText().toString();
  
      ArrayList&lt;Image&gt; dataList = new ArrayList&lt;Image&gt;();
  
      if (image == null)
          image = new Image(imageName, date, dataList);
      else
          image.update(imageName, date, dataList);
  
      Log.i("IMAGE DETAILS CHANGED", image.toString());
  }
  </code></pre>
  
  <p>I have 4 images on my main activity. clicking on one of them opens up a form where you can enter their details and on back button pressed they sow up below the image themselves only the image name and date. but this shows up the same for all the images. i wanna know how to make it so that only the image that i clicked on gets the details passed to it and not the other images. so separateness passing the data to the individual images is what i wanna figure out.</p>