Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 225
userM1433372 Avatar asked Sep 14 '15 11:09

userM1433372


Video Answer


2 Answers

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.

like image 155
wojtek.kalicinski Avatar answered Sep 19 '22 21:09

wojtek.kalicinski


As far as I know, the only condition under which the system restores the state of an Activity when it's completely destroyed is when the system had to destroy that Activity to recover system memory. In all other cases (force process to stop, reinstallation of the app, restart of the device) the state is lost.

About the reinstallation, you have to consider that when you install a new version of the app, you have probably changed or removed one or more activities, and the state of the old activities cannot probably match the state of the new ones. Suppose for example that in a single Activity app, you have a TextView with id "@+id/my_text". After few days, you decide to remove the TextView and assign the id "my_text" to another View - for example a Spinner: how could the system restore the text of the TextView in a Spinner?

like image 22
Mimmo Grottoli Avatar answered Sep 18 '22 21:09

Mimmo Grottoli