0

I have an app which is already in play store. and I'm working on an update right now. suppose my current app version is 1.0.4, and I'm releasing 1.0.5. so for the next updation from 1.0.4 I have to clear the preference. that is if user has already 1.0.5 version and for future update suppose 1.0.6 the preference should not clear. is there any way to do this ?

Precisely, I have to clear preferences first update after 1.0.4

any help will be appreciated

EDIT

Actually there is an BroadcastReceiver with intent filter

<action android:name="android.intent.action.PACKAGE_REPLACED" />

if I get previous version inside onReceiver of this broad cast I can easily clear preference.

droidev
  • 7,352
  • 11
  • 62
  • 94

1 Answers1

1

I would add a version key pair in your SharedPreferences while releasing 1.0.5, and reset all SharedPreferences from devices in this update.

I guess you know how to totally reset your SHP:

yourSharedPreferences.edit().clear().apply();

Or, sync case:

yourSharedPreferences.edit().clear().commit();

While releasing to 1.0.6 you can look for your version key pair. In case it exists, it should be 1.0.5. On the contrary, you are updating from 1.0.4 and you can reset your SHP like in the previous step.

I hope this would help you!

Juan Aguilar Guisado
  • 1,687
  • 1
  • 12
  • 21
  • that is a solution actually, but I am trying to do something with broadcast receiver if i get the previous version here, I can reset preference then, if I am adding an extra key pair, I have to check in each startup of application – droidev Oct 15 '15 at 12:18
  • Yes, you are right. You would have to check this every App start, but after a briefly search what you are trying to do (interesting approach) seems to be a difficult thing :( http://stackoverflow.com/q/13193214/3886983 – Juan Aguilar Guisado Oct 15 '15 at 12:49
  • anyhow this is not an answer as I expected, but since there is other ways to do this. I have to accept this, instead of keeping the version I would like to store a boolean. So that can increases little performance. – droidev Oct 15 '15 at 15:36