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?
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?
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 {
}
Make it parcleable, pretty easy.
Have a look on this posting: Arraylist in parcelable object
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");