Serialization exception on Samsung Galaxy S5

In my application, I pass a data object from one Activity to another. The code is pretty simple on the first Activity :

  Intent intent = new Intent(getActivity(), BlablaActivity.class); intent.putExtra(Values.KEY_ITEM, item); 

and when taking Activity :

  Intent intent = getActivity().getIntent(); item = (Item) intent.getSerializableExtra(Values.KEY_ITEM); 

The Advertising class is also very simple:

 public class Advertising implements Serializable { private static final long serialVersionUID = -7292860618498106953L; private Content content; private Anchor anchor; private String target; private String id; // ... } 

And the Anchor class, which seems to be causing this problem:

 public class Anchor implements Serializable { private static final long serialVersionUID = 7360857799761417956L; public String value; public String label; // ... } 

I get the following exception only for Samsung Galaxy S5 (sm-g900f):

Called: java.lang.IllegalArgumentException: field de.mycompany.model.Advertising.anchor
has type de.mycompany.model.resultandexpose.Anchor obtained by de.mycompany.model.resultandexpose.Anchor

and I cannot understand this, the expected class is the actual class. This seems to be another problem specific to Samsung. Has anyone experienced this and knows to fix it or has an idea, what is the reason for this?

EDIT:

  • Yes, I use Proguard. The proguard file is as follows:

    -keepattributes ** -keep class! android.support.v7.internal.view.menu. , {*;} -dontpreverify -dontoptimize -dontshrink -dontwarn **

The second line is a workaround for a known bug on Samsung devices and should not concern any classes other than those in the package android.support.v7.internal.view.menu.* ,

  • The serialVersionUID of the Anchor class is unique in all of my classes.

  • Switching to Parcelable would mean a massive overhaul of the entire project. Passing objects as Serializable should work on all devices.

  • The Anchor class is just one example of this error that occurs on several other classes that basically look the same or very similar. So the point is not in one class, but in a more general problem.

+6
source share
2 answers

I had a simillar problem and I found that with the lolipop update on s5 galaxy devices, samsung uses a listenable multidex implementation. You can check my question here explaining the problem. Someone answered my question, but I did not check if it still works. Maybe this will help you.

+1
source

You should look at Parcelable to pass an object between two actions with an intent.

You can look at this tutorial that explains how this works, I also suggest taking a look at the Android Doc.

+1
source

Source: https://habr.com/ru/post/988697/


All Articles