tags:

views:

187

answers:

3

I have an activity that when started needs access to two different ArrayLists. Both Lists are different Objects I have created myself.

Basically I need a way to pass these objects to the activity from an Intent. I can use addExtras() but this requires a Parceable compatible class. I could make my classes to be passed serializable but as I understand this slows down the program.

What are my options?

Can I pass an Enum?

As an an aside: is there a way to pass parameters to an Activity Constructor from an Intent?

+2  A: 

Basically I need a way to pass these objects to the activity from an Intent.

Why?

What are my options?

Don't pass these objects to the activity from an Intent. Instead, hold onto these objects in a central location outside of your activities, such as a database, service, custom Application object, or (in a pinch) static data member. Have your activities (or other components) get what they need from the central location.

Can I pass an Enum?

Since there is no putExtra() that takes an Enum, no.

As an an aside: is there a way to pass parameters to an Activity Constructor from an Intent?

Activities should not be implementing constructors. Hence, there is no way to pass parameters to an activity constructor from an Intent.

CommonsWare
A: 

I think your best bet is going to be to convert those lists into something parcelable such as a string (or map?) to get it to the Activity. Then the Activity will have to convert it back to an array.

Implementing custom parcelables is a pain in the neck IMHO so I would avoid it if possible.

Brad Hein
+2  A: 

Don't use enums. Reason #78 to not use enums. :) Use integers, which can easily be remoted through Bundle and Parcelable.

hackbod