• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bundles

 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reckon my question would be more for Android Java as suppose to Java.

1. What are bundles? What is a best way of describing it?

2. What is the lifetime of a bundle like? (as in when compared to an Activity?) Does the lifetime of a bundle terminate when the Activity dies, or does it get stored somewhere in memory?

3. What's the point of having Bundles? What is it's usage?

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Do wrote:I reckon my question would be more for Android Java as suppose to Java.

1. What are bundles? What is a best way of describing it?

They are maps. You store data of various types to String keys.

Mark Do wrote:2. What is the lifetime of a bundle like? (as in when compared to an Activity?) Does the lifetime of a bundle terminate when the Activity dies, or does it get stored somewhere in memory?

I guess that depends on the use case. But the Bundles you give to Intents and when you save instance state can live longer than the Activity. They can be stored (in memory or on disk I am not sure) so they are available if the Activity is taken out of memory and needs to be re-created. I am not sure if they get destroyed when the Activity is formally finish()ed.

Mark Do wrote:3. What's the point of having Bundles? What is it's usage?

Bundles let you transfer (nearly) arbitrary data from one activity to the next through the Intent used to start the activity. Similarly you can tranfer data between processes and Services. It also lets you store arbitrary data when an activity stops and is restarted (for example when it the phone is restarted or memory issues force the activity to close temporarily) via the onSaveInstanceState(Bundle)/onCreate(Bundle) methods. You either put standard types in (Strings, ints, booleans, etc...), Parcelables (classes that you implement which know how to write to or from a Parcel), or Serializable objects (which can be written to or read from an ObjectStream). Once the data is sent to the Bundle it can be stored or transported, then read from the Bundle when needed, perhaps in a different process or perhaps after being stored for a while when the activity is restarted in a different configuration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic