我在一个 Activity 中执行以下操作:
intent.putExtra("searchRegion", searchRegion);
Log.d("AAA", "Puttin searchRegion: " + searchRegion.toString());
和接收 Activity :
SearchRegion searchRegion = (SearchRegion) getIntent().getSerializableExtra("searchRegion");
Log.d("AAA", "rcv searchreg " + searchRegion.toString());
结果是:
Puttin searchRegion: mypackage.SearchRegion@3b41ba0
rcv searchreg mypackage.SearchRegion@22655d14
当我想知道序列化后我的 SearchRegion 对象的 Observer
去了哪里时,我意识到了这一点。
我有两个问题:
- 通过
Intent
序列化我的对象时到底发生了什么?接收端的对象和发送端的对象不一样吧? - 我可以在使用
Intent
的整个序列化过程中保留对象的Observer
吗?
最佳答案
What exactly happens when serializing my object through the Intent?
这些对象持有的数据,加上关于对象类的元数据,被写入一个流,然后从该流中重构。
The object on the receiving end is not the same as the object on the sending end, right?
正确。
Can I keep the Observers of an object throughout serialization with Intent?
没有。
关于java - 序列化对象会发生什么?如何在整个序列化过程中保持观察者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24630639/