Passing :
intent.putExtra("MyClassObject", obj);
To retrive
getIntent().getSerializableExtra("MyClassObject");
# 3 楼答案
您需要使用Android Parcelable
什么是包裹:
Parcel is a light weight IPC (Inter Process Communication) data structure, where you can flatten your objects in byte stream.
Parcelable is an Android specific interface where you implement the serialization yourself. It was created to be far more efficient that
Serializable, and to get around some problems with the default Java
serialization scheme.
如何使用Parcelable:
1.Implement an Interface android.os.Parcelable which will make Objects of Parcelable class.
2.Overwrite two methods of android.os.Parcelable Interface as bellow :
describeContents()- define the kind of object you are going to Parcel.
writeToParcel(Parcel dest, int flags)- actual object serialization/flattening happens here. You need to individually Parcel
each element of the object.
3.Define a variable called CREATOR of type Parcelable.Creator
Serialization in Java is far +too slow+ to satisfy Android’s interprocess-communication requirements. So the team built the
Parcelable solution. The Parcelable approach requires that you
explicitly serialize the members of your class, but in the end, you
get a much faster serialization of your objects.
The problem with Serializable is that it tries to appropriately handle everything under the sun and uses a lot reflection to make
determine the types that are being serialized.
# 1 楼答案
你们班:
意图传递:
# 2 楼答案
一个选项是让您的类实现可序列化接口,然后您可以使用putExtra(Serializable..)在intent extra中传递对象实例Intent#putExtra()方法的变体
# 3 楼答案
您需要使用Android Parcelable
什么是包裹:
如何使用Parcelable:
检查本教程:
可打包与序列化
# 4 楼答案
使用可序列化对象,并将其直接保存在Bundle或Intent中
发送对象
你们班呢
到达另一端
已更新
也可以将数据作为可包裹对象发送。但是记住
如果要通过目的向另一个活动发送非基本类型的数据/对象,则必须序列化或实现该对象的Parcelable。首选技术是可包裹的,因为它{}