0
ArrayList <Car> CarList = new ArrayList<Car>();  
Car carItems= new Car(carno, cartype, date, arriveTime, carcost);   
CarList .add(carItems);

Now I want to pass carList through Intent?

Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
user2799407
  • 549
  • 1
  • 6
  • 16

3 Answers3

1

For passing the the object:

Bundle bundle = new Bundle();
ArrayList <Car> CarList = new ArrayList<Car>();  
Car carItems= new Car(carno, cartype, date, arriveTime, carcost);   
CarList.add(carItems); 
bundle.putSerializable("carList",carList);
intent.putExtras(bundle);

For retrieving:

ArrayList <Car> CarList = getIntent().getSerializableExtra("carList");

Make sure Car is serializable:

public class Car implements Serializable {

}
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48
  • It show error as The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, List) – user2799407 Mar 14 '14 at 10:19
  • Have you made your `Car` class implement [Parcelable](http://developer.android.com/reference/android/os/Parcelable.html) – betteroutthanin Mar 14 '14 at 10:23
  • public class Car implements Parcelable and I bave implemented public int describeContents(), public void writeToParcel(Parcel dest, int flags) – user2799407 Mar 14 '14 at 10:25
0

Make it parcleable, pretty easy.

Have a look on this posting: Arraylist in parcelable object

Community
  • 1
  • 1
Kitesurfer
  • 3,438
  • 2
  • 29
  • 47
0

It seems that you actually have to make Car a Parcelable.

To add it to the Intent, use putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)

Edit

To get the list in the other activity, do this in onCreate or onNewIntent:

Intent i = getIntent();
ArrayList<Car> cars = i.getParcelableArrayListExtra("extraKeyUsedWithPutExtra");
Ridcully
  • 23,362
  • 7
  • 71
  • 86