0

I'm trying to pass a list of events from one Activity to another one using intent, this is how I tried to do it:

on Activity 1:

ArrayList<Event>  eventsSelected= new ArrayList();
eventsSelected.add(new Event(Color.RED, dateClicked.getTime(), "event1"));
eventsSelected.add(new Event(Color.RED, dateClicked.getTime(), "event2"));
eventsSelected.add(new Event(Color.RED, dateClicked.getTime(), "event3"));
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("eventsSelected", eventsSelected);
startActivity(i);

but I didn't find how to get it on the second activity, I tried it this way but it didn't work :

on Activity 2:

Intent intent = getIntent();
ArrayList<Event> selectedDates = intent.getStringArrayListExtra("eventsSelected");
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57

4 Answers4

0

You need to implements Serializable to your object class

public class Event implements  Serializable {
}

Also

i.putExtra("eventsSelected",eventsSelected);
John Joe
  • 10,340
  • 9
  • 48
  • 104
0

just to clarify it works this way

ArrayList<Event> eventsSelected = new ArrayList<Event>();
intent.putExtra("eventsSelected", eventsSelected);

and in the second class

ArrayList<Event> eventsSelected = (ArrayList<Event>) getIntent().getSerializableExtra("eventsSelected");
0

try

Bundle data=getIntent().getExtras() ;  
ArrayList<Event> aaa= (ArrayList<Event>) data.get("eventsSelected");
jigar savaliya
  • 416
  • 8
  • 19
0

Your have to must have to implements class Parcelable or Serializable while you are passing it through an Intent. look at my this and this answers. Hope it will help you!!

Ajeet Choudhary
  • 1,751
  • 1
  • 11
  • 37