Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, How to put an ArrayList<myObject> in an Intent?

I have two Activities, in the first one, I instanciate an ArrayList of Object myObject. In the second activity, i need to get this Arraylist. I don't know how to do that with an intent ?

(Object is a class I have created)

Thanks in advance.

like image 627
Gen Avatar asked Jul 21 '11 07:07

Gen


2 Answers

If you make your Object class implement Parcelabel you can pack your arraylist into the bundle you send with the intent

see this link for an example

like image 75
getekha Avatar answered Sep 28 '22 07:09

getekha


Usually you use Bundle objects to pass information between Activities, but these only allow for simple type objects. Typically, for passing more complex object types you generally have to construct a static context of some kind and set your values on that, which is then available to the second activity. It feels dirty, but I've got over it in my apps now.

like image 28
Mark Fisher Avatar answered Sep 28 '22 07:09

Mark Fisher