Reputation: 4115
I have my app in PlayStore. When I update my app with new exported apk SharedPreference Key is changing. You can understand it by seeing the json strings given below.
I am saving an object in shared preference as given below.
Saving user details in SharedPreference.
Gson gson = new Gson();
String json = gson.toJson(user);
prefsEditor.putString("user", json);
prefsEditor.commit();
Getting details from sharedPrefernce
Gson gson = new Gson();
String json = myPref.getString("user", null);
Log.v(MainActivity.TAG, "Json == "+json);
user = gson.fromJson(json, User.class);
Please have a look on the jsons i am printing, the keys are changed to 'a','b' etc.
When I run normally the JSON is Json == {"accessToken":"12345678","country":"India","countryCode":"91","email":"","firstName":"Aneesh","lastName":"Kamalone","nickName":"Kamalone","notificationId":"","phoneNumber":"******","profilePic":"","uniqueId":"","userId":"*****","userLatitude":14.9,"userLogitude":79.6}
When I update with the previous version the json is Json == {"a":"****","b":"Aneesh","c":"Kamalone","d":"Kamalone","e":"**********","f":"","g":"APA91bElQulddjH6xSR0WH8nfBGcFIbn-sRe-ChkhIx1c6Il05_wwGrTLm1QDNsr6TtaG1bIrICmXKhK1I8ZVzo0cqvwPWSj4NrxJKyzTsdPpNlizmGMaJfMWj_rjteP6yNoRFeDAZYfTCyhx-7WUAmTT2rX0q1S6Q","h":"","i":"12345678","j":"India","k":"91","l":14.9,"m":79.6,"n":""}
Upvotes: 0
Views: 216
Reputation: 4115
It is my mistake.proguard was not enabled when I was exporting the APK.
Upvotes: 0
Reputation: 2495
It seams that you are using proguard and it obfuscates your User
class.
Gson
uses field names as keys by default. So I suggest to use @SerializedName
annotation for correct json mapping
Upvotes: 1