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
See how fast Parcelable is than Serializable.
from WHY WE LOVE PARCELABLE
from Parcelable vs Serializable
If you need serialization for i.e. storage purposes but want to avoid the speed penalty of reflection incurred by the Serializable interface you should explicitly create your own serialization protocol with the Externalizable interface.
When properly implemented this matches the speed of Parcelable and also accounts for compatibility between different versions of Android and/or the Java platform.
This article might clear things up as well:
What is the difference between Serializable and Externalizable in Java?
On a sidenote, it is also the fastest serialization technique in many benchmarks, beating Kryo, Avro, Protocol Buffers and Jackson (json):
http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking
Serializable
is comically slow on Android. Borderline useless in many cases in fact.Parcel
andParcelable
are fantastically quick, but its documentation says you must not use it for general-purpose serialization to storage, since the implementation varies with different versions of Android (i.e. an OS update could break an app which relied on it).The best solution for the problem of serializing data to storage at a reasonable speed is to roll your own. I personally use one of my own utility classes which has a similar interface to
Parcel
and which can serialize all the standard types very efficiently (at the expense of type safety). Here's an abridged version of it :