Hi Dianne

My custom serialization methods get called if I do the 
serialization/deserialization myself by writing/reading the object to/from a 
byte[].
If the same object is written using putSerializable the methods are NOT 
called. So my assumption is that the Bundle is never actually 
serialized/deserialized but just kept in memory?
So Android IS doing something to stop my code from working (or rather it 
doesn't do it although the docs don't say it's doing standard Java 
serialization, that's just something I would expect it to do).

Here's some sample code that will allow to follow my argumentation:

*public class SerializationActivity extends Activity {*
*
*
* public static class PersistentObject implements Serializable {*
* private static final long serialVersionUID = -8258412687839520234L;*
* private long id = (long) (Math.random() * 100000);*
*    private void writeObject(ObjectOutputStream out) throws IOException {*
*     out.defaultWriteObject();*
*     System.out.println("writeObject() called for: " + id);*
*    }*
*    private void readObject(ObjectInputStream in) throws IOException, 
ClassNotFoundException {*
*     in.defaultReadObject();*
*     System.out.println("readObject() called for: " + id);*
*    }*
*    private void alive() {*
*     System.out.println("I'm alive and my id is: " + id);*
*    }*
* }*
* *
* private PersistentObject putSerializable = new PersistentObject();*
* private PersistentObject serializedObject = new PersistentObject();*
* *
* @Override protected void onCreate(Bundle savedInstanceState) {*
* super.onCreate(savedInstanceState);*
* if (savedInstanceState!=null) {*
* putSerializable = (PersistentObject) 
savedInstanceState.getSerializable("putSerializable");*
* putSerializable.alive();*
* serializedObject = (PersistentObject) deserializeObject((byte[]) 
savedInstanceState.getSerializable("serializedObject"));*
* serializedObject.alive();*
* }*
* }*
*
*
* @Override protected void onSaveInstanceState(Bundle outState) {*
* super.onSaveInstanceState(outState);*
* ** **System.out.println("onSaveInstanceState() called");*
* putSerializable.alive();*
* outState.putSerializable("putSerializable", putSerializable);*
* serializedObject.alive();*
* outState.putSerializable("serializedObject", 
serializeObject(serializedObject));*
* }*
*
*
* public byte[] serializeObject(Serializable s) {*
* try {*
*    ByteArrayOutputStream baos = new ByteArrayOutputStream();*
* ObjectOutputStream oos = new ObjectOutputStream(baos);*
* oos.writeObject(s);*
* return baos.toByteArray();*
* } catch (IOException e) {*
* return null;*
* }*
* }*
*
*
* public Object deserializeObject(byte[] in) {*
* try {*
*    ByteArrayInputStream bais = new ByteArrayInputStream(in);*
* ObjectInputStream ois = new ObjectInputStream(bais);*
* return ois.readObject();*
* } catch (Exception e) {*
* return null;*
* }*
* }*
*}*

Cheers
Emanuel Moecklin
1gravity LLC

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to