1

When an app is uninstalled, is the data in its SharedPreferences database deleted?

If not, without a device being rooted, is there any way to clear that data? (Or at least view it?)

  • SharedPreferences is located in the data directory of the app which gets deleted during uninstallation. Do you have a case where it was not deleted by the system? – Firelord Jun 12 at 20:36
  • @Firelord I was reading up on Stack Overflow on how to make an app with a "trial period". One of the answers recommended writing data to SharedPreferences, because they claimed it can remain when an app is uninstalled. That doesn't match what I remembered, so I thought it best to ask. – RockPaperLizard Jun 12 at 20:41
  • SharedPreferences are backed by Google if the app participates in the backup. It would be best if you clarify whether "they" assumed your app would be backed up. – Firelord Jun 13 at 5:58
  • @Firelord I don't back up anything to Google (well, not intentionally), so I'm looking up what you're referring to. I see a "Back up my data" option deep within Android Settings... is that it? – RockPaperLizard Jun 13 at 6:34
  • 1
    If auto backup is the issue, then you can clear the app data after reinstalling to delete all the shared preferences. – Andrew T. Jun 14 at 10:03
2

SharedPreferences are actually saved in a file in the app private directory: /data/data/package_name/shared_prefs/somefilename.xml

When an app is installed this directory and file are automatically created. When an app is uninstalled this directory is deleted along with its parent /data/data/package_name UNLESS the app is uninstalled in order to update it. From command line this is done using the flag -k or -r that is

adb uninstall -k package_name - Keep the data and cache direct­ories around after removal

adb uninstall -r package_name - Reinstall an existing app, keeping its data

1

SharedPreferences database always deleted when app is uninstalled. but In Manifest
android:allowBackup="true" If allowBackup is true then data is not clear even if application is uninstall then install. so always keep allowBackup false when data do not want store.

  • Thank you. What is the best way to keep allowBackup as false? – RockPaperLizard Jun 14 at 6:35
  • 1
    @user298642 The allowBackup flag usually only affects the adb backup. Do you have a source that backs your answer? – Robert Jun 14 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.