java - How to pass an object of a class using an intent? -


how pass object of class using intent?

ex.

myclass mc = new myclass(); 

how can pass mc using intent?

you need use android parcelable

what parcel:

  • parcel light weight ipc (inter process communication) data structure, can flatten objects in byte stream.

  • parcelable android specific interface implement serialization yourself. created far more efficient serializable, , around problems default java serialization scheme.

how use parcelable :

1.implement interface android.os.parcelable make objects of parcelable class.

2.overwrite 2 methods of android.os.parcelable interface bellow :

  • describecontents()- define kind of object going parcel.

  • writetoparcel(parcel dest, int flags)- actual object serialization/flattening happens here. need individually parcel each element of object.

3.define variable called creator of type parcelable.creator

check tutorial :

http://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.html

parcelable vs serialization

  • serialization in java far +too slow+ satisfy android’s interprocess-communication requirements. team built parcelable solution. parcelable approach requires explicitly serialize members of class, in end, faster serialization of objects.

  • the problem serializable tries appropriately handle under sun , uses lot reflection make determine types being serialized.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -