2

How do you pass an instance of ArrayList<ArrayList<HashMap<String, String>>> from one Android activity to another via an instance of Bundle?

(I could use JSON strings. I'd like to know if there are better ways.)

Thanking you kindly in advance.

2 Answers 2

2

You can pass it as an extra in the Intent that you use to fire up the new activity. Since ArrayList implements Serializable, you don't have to do anything special to feed it to Intent.putExtra().

Sign up to request clarification or add additional context in comments.

3 Comments

ya passing Arraylist as object is a good way.. no need for json and all...so 1 up..
@Ganapathy: Right - I see. Thanks, and for the full answer too.
Please note serialization is really inefficient. This data structure has the potential to hold a lot of elements, in which case the inefficiency of serialization can really bite you. I strongly recommend not doing this.
1

In general it is not good to pass too many or too large data between activities via Intents. It's better to store them somewhere centrally and pass a lightweight identifier or something like this, so the other activity can retrieve them from the store.

E.g. you can use an Application class to store these data. An application class is always available as long as you application is running. You get it from each Activity by calling the getApplication() method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.