8

I'm new to Android and while going through a tutorial on saving Activity state to a Bundle, I noticed that instead of accepting the more generic List interface, Bundle's put methods are expecting ArrayLists.

Example:

Bundle.putCharSequenceArrayList(key, value)
Bundle.putIntegerArrayList(key, value)
Bundle.putParcelableArrayList(key, value)
Bundle.putStringArrayList(key, value)

Most of us are familiar with item 52 of Effective Java suggesting that objects must be refered to by their interface, so I am wondering what was the reason behind this API decision.

Is ArrayList perhaps the preferred list implementation in Android?

asked Jul 24, 2013 at 3:56

1 Answer 1

9

Just a guess: Maybe Bundele-content must be be serializable and not every Lists implementation is serializable.

From sdk-doc public Bundle.Bundle (ClassLoader)

 Constructs a new, empty Bundle that uses a specific 
 ClassLoader for instantiating Parcelable and Serializable objects.
answered Jul 24, 2013 at 4:10
2
  • makes sense! i'll wait a while more in case someone has a definitive answer. Commented Jul 24, 2013 at 5:33
  • the more I go through the tutorial, the more this answer makes sense. so I am accepting it :-) Commented Jul 24, 2013 at 10:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.