Search code examples
androidserializationinstancestate

Is the Android activity instanceState cleaned during app upgrade?


In the instanceState of an activity we store a Serializable (bundle.putSerializable). In a crash report from the Play Store we saw the following stack trace:

Caused by: java.lang.ClassNotFoundException: o.ণ
at java.lang.Class.classForName(Class.java)
at java.lang.Class.forName(Class.java:308)
at android.os.Parcel$2.resolveClass(Parcel.java:2373)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at android.os.Parcel.readSerializable(Parcel.java:2381)

Our code is obfuscated by DexGuard. It looks like Android is able to serialize the class but not able to deserialize the class.

The only reason we currently can think of is an upgrade of the app (via de Play Store). Between the version the class is changed (because of Dexguard) making a deserialization impossible.

So, my question is: does Android clean all instanceState of an app during the upgrade of an App or not?


Solution

  • You shouldn't include custom classes in the saved instanceState if there is any chance that those classes will change (even if it's only DexGuard shuffling names around). The system persists some information about recent activities and may try to reuse it across upgrades.