android - Send a Bundle over the network -
i'm trying send bundle
on network 1 device using objectinputstreams
, such. problem bundle
not serializable. there simple way make happen? want use bundle
because can sending sorts of types (string, int, parcelables, lists, etc)
you should not serialize bundle, because not guarantee version compatibility. if can make sure every device uses exact same version should fine. not recommend this. every api states should not done!
parcel not general-purpose serialization mechanism. class (and corresponding parcelable api placing arbitrary objects parcel) designed high-performance ipc transport. such, not appropriate place parcel data in persistent storage: changes in underlying implementation of of data in parcel can render older data unreadable.
https://developer.android.com/reference/android/os/parcel.html
but if want it, here way implement it:
bundle in = ...; outputstream os = ... parcel p = parcel.obtain(); //create empty parcel object in.writetoparcel(p, 0); //saving bundle parcel os.write(p.marshall()); //write parcel stream
Comments
Post a Comment