[英]Detect when object is getting serialized
I have a class / object that uses a listener interface. 我有一个使用侦听器接口的类/对象。 As far as I understand, those can't be serialized, at least I get an NotSerializableException when trying to.
据我了解,那些无法序列化,至少在尝试时会收到NotSerializableException。
Can I detect from within the object when I's gettings serialized (some form of callback) so I can remove the listener from the object? 序列化(某种形式的回调)时,是否可以从对象中检测到,以便可以从对象中删除侦听器?
I know I can set the listener to null from outside of the object, but it would be easier the way I described. 我知道我可以从对象外部将侦听器设置为null,但是这样描述会更容易。
Don't do this. 不要这样 make your class implement
Parcelable
and provide the serialization methods yourself. 使您的类实现
Parcelable
并自己提供序列化方法。 Then you can decide which members get serialized and how that is done. 然后,您可以决定要序列化哪些成员以及如何进行序列化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.