title: How to prevent SharedPreferences from loading corrupt data
body: <p>I have a custom class with 3 <code>String</code> fields (<code>arg1</code>, <code>arg2</code>, <code>arg3</code>) and getters/setters. In <code>Fragment</code> there are 3 <code>editText</code> fields that create a new Object of custom class. And I also have an <code>ArrayList</code> of  custom objects (max capacity is 15, but its usualy around 1-3) that is stored in <code>SharedPreferences</code>.<br>
  Everything worked fine until last update in which I only changed some UI design features in <code>xml</code>. Not a single line of Java code was changed, especialy those that have something to do with Custom objects, <code>ArrayList</code> or <code>SharedPrefs</code>.<br>
  Now some users, after updating my app, get corrupted first (or in most cases, only) entry of <code>ArrayList</code>, and <code>arg1</code> is <code>&quot;&quot;</code> or <code>null</code>. <br>
  The worst thing is they are displayed the value of <code>arg2</code> where is explicitly called <code>textView.setText(arg1)</code>.<br><br>
  Im saving my <code>SharedPrefs</code> in <code>onStop()</code> and restoring it in <code>onCreate()</code> and I'm using <code>Gson/Json</code> for storing. In 99,9% everything is fine, but after recent update, some users reported this problem.</p>
  <p>What's going on, and how to prevent it from happening in the future?</p>
  <p>EDIT:
  What about the fact that I set my <code>ArrayList</code> to be <code>public static</code>, so I can use it elsewhere, would it be a problem? Also since I can't debug production app, I've noticed that either args or their values have moved like <code>MyCustomObject(&quot;val1&quot;, &quot;val2&quot;, &quot;val3&quot;)</code> is now  <code>MyCustomObject(&quot;val2&quot;, &quot;val3&quot;, &quot;???&quot;)</code> I dont know what last value is. Is it <code>val1</code> or <code>&quot;&quot;</code></p>