As I understand, Bundle
and Parcelable
belongs to the way Android performs serialization in. It is used for example in passing data between activities. But I wonder, if there are any benefits in using Parcelable
instead of classic serialization in case of saving state of my business objects to the internal memory for example? Will it be simpler or faster than the classic way? Where should I use classic serialization and where better to use bundles?
相关问题
- 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
Based on this article http://www.mooproductions.org/node/6?page=5 Parcelable should be faster.
Not mentioned in the article, is that I don't htink that serializable objects will work in AIDL for remote services.
I just use GSON -> Serialise to JSON String -> Restore Object from JSON String.
From "Pro Android 2"
It seems that nowadays the difference isn't so noticeble, at least not when you run it between your own activities.
According to tests shown on this website , Parcelable is about 10 times faster on newest devices (like nexus 10), and is about 17 faster on old ones (like desire Z)
so it's up to you to decide if it worths it.
maybe for relatively small and simple classes, Serializable is fine, and for the rest, you should use Parcelable
Parcelable is mainly related to IPC using the Binder infrastructure, where data is passed as Parcels.
Since Android relies a lot on Binder for most, if not all, IPC tasks, it makes sense to implement Parcelable in most places, and especially in the framework, because it allows pass an object to another process if you need that. It makes objects "transportable".
But if you have a non Android-specific business layer which extensively use serializables to save object states, and only need to store them to the file system, then I think that serializable is fine. It allows to avoid the Parcelable boiler-plate code.
Also Parcelable offers custom implementation where the user gets an chance to parcel each of his objects by overriding the writeToParcel(), However serialization does not this custom implementation as its way of passing data involves JAVA reflection API.