10

Is it possible to to put an object of type Object into an intent as a Extra? I have a variable of type object and won't know until it is assigned a value as to what the object datatype is. Maybe something to do with serialization or as a bundle i'm not sure? And then in the next activity how do I then get this value in order to store it in an ArrayList<Object> ?

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
SamRowley
  • 3,435
  • 7
  • 48
  • 77
  • [This stackoverflow question](http://stackoverflow.com/questions/4249897/how-to-send-objects-through-bundle/13819217#13819217) will help. – Rupesh Yadav Dec 11 '12 at 11:21

1 Answers1

17

Bundle by way of Intent#putExtra does not have any function to add an Object. You can only pass in a Parcelable or a Serializable object. Any object you want to pass via an Intent must implement one of those interfaces. It's recommended to implement Parcelable there is a brief guide here: Pass by value Parameters using Parcelables.

Also this question has more helpful answers: How to send an object from one Android Activity to another using Intents?

Community
  • 1
  • 1
Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • How can this method work for an object of type I don't know at the time of parceling? – SamRowley Jan 07 '11 at 17:12
  • This could be expanded a bit I feel. Technically as long as the Object is parcelable or serializable then you can call the toArray function of the List and send it that way. – Jackie Nov 11 '13 at 13:30