I'd like to pass a custom Object from one activity to another, the Object consists of a String and a List of another custom Object which consists of an array of strings and an array of ints. I've read https://stackoverflow.com/a/2141166/830104, but then I've found this answer https://stackoverflow.com/a/7842273/830104. Which is better to use Bundle or Parcelable? What is the difference? When should I use this each?
Thanks for your replies,
Dan
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Parcelable
andBundle
are not exclusive concepts; you can even deploy both on your app at a time.[1] Term
Parcelable
comes with Serialization concept in Java (and other high-level language such as C#, Python,...). It ensures that an object - which remains in RAM store - of suchParcelable
class can be saved in file stream such as text or memory (offline status) then can be reconstructed to be used in program at runtime (online status).In an Android application, within 2
independent activities
(exclusively running - one starts then other will have to stop):There will be NO pointer from current activity to refer to previous one and its members - because previous activity is stopped and cleared out form memory; so that to maintain object's value passed to next activity (called from
Intent
) the object need to beparcelable
(serializable
).[2] While
Bundle
is normally the Android concept, denotes that a variable or group of variables. If look into lower level, it can be considered as HashMap with key-value pairs.Conclusion:
Bundle
is to store many objects with related keys, it can save any object in native types, but it doesn't know how to save a complex object (which contains an ArrayList for example)Parcelable
class is to ensure a complex instance of it can beserialized
andde-serialized
during runtime. This object can contains complex types such as ArrayList, HashMap, array, or struct,...[UPDATED] - Example:
In source activity:
In destination activity: