1

I need to delete the shared preference file from android whenever user downloads the newer version of the app or re-installs the application. How can I achieve this?

Thanks in Advance !!

Cheers, Prateek

2 Answers 2

6

How can I achieve this?

You have no way to detect a reinstall. Fortunately, that never occurs except during development, AFAIK.

To detect a version upgrade, store a copy of your versionCode in a preference. Compare it to the running copy when your code starts up. If your app is newer than the versionCode in the preference, your app has been updated, and you can do whatever you feel you need to do.

Note, though, that this is rather unusual behavior, and users may give you poor ratings on the Market if they feel that they are losing information because of an upgrade.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply !! I just store few values in the preference file, whose copy is maintained at my server end. But, the values changes when the app is reinstalled. But there is no way to remove the shared preference file on updating. Users won't loose any information, as those are stored at the server end and once the application is reinstalled, it will be fetched from the server.
@Prateek Jain: Let me repeat: there is no "reinstall" for normal users. Users will uninstall the app, then install it fresh. The act of uninstalling will remove your SharedPreference data. You will need to handle the delete-file-on-update yourself, as the vast majority of Android applications should not be doing that.
Got it !! I wanted to remove the shared preference file on updating the application to newer versions, which I can do by your suggested method of checking the "version code". Thanks !!
0

Not only! In fact, to no longer have shared preferences data once the application has been reinstalled, you must enter in Manifest.xml:

<application android:allowBackup="false".../>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.