Android and passing nested ArrayLists via Bundles
How do you pass an instance of ArrayList&l开发者_如何学运维t;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.
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()
.
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.
精彩评论