0

By default Shared Preferences on Android are being able to be deleted by phone setup. Is it possible to block this ?. Basically i would like to store a Shared Preference as defined on Android documentation but not to allow to delete them by any reason. Ie Phone Setup, App update nor App uninstall. If this is not possible, which storage mechanism would you suggest to do this. I need to store is primitive data mostly.

I am making an application where I need to collect certain data from user and ensure he will have just one opportunity to provide it, otherwise she would be cheating. I agree, best option is to store the data provided on my server but that approach would not work if user turn off internet. I understand both requirements might be very difficult to meet.

RobertoAllende
  • 8,744
  • 4
  • 30
  • 49
  • 2
    If you wish to comment on an answer, click the "add comment" link below the answer, not the "add comment" link below the question. – CommonsWare Aug 12 '12 at 23:11
  • 1
    hey buddy i fond 100% success way to prevent sharedpreferace to being cleared see my answer here http://stackoverflow.com/questions/20300166/how-to-prevent-a-shared-preferance-from-being-clear-in-setting – Hardik Feb 07 '14 at 08:44

2 Answers2

5

It is possible to delete any data stored on the phone.

Shared preferences and files not saved to the SD card will be deleted when the app is uninstalled.

Files saved to the SD card will persists after uninstall, however, the user will have access to read, over-write, and delete these files at will.

If you need truly permanent storage the best way forward would be to store the data remotely on a server that you control.

slayton
  • 20,123
  • 10
  • 60
  • 89
  • see my answer it is possible http://stackoverflow.com/questions/20300166/how-to-prevent-a-shared-preferance-from-being-clear-in-setting – Hardik Jan 03 '15 at 09:08
1

What you're suggesting of doing sounds dangerous to me.

Bear in mind that when you're programming, you're programming within a certain environment. The operating system will restrict aspects of what you can and can't do, to keep consistency across applications, provide security etc.

If you're wanting to use shared preferences as a means of providing trials for applications, or some other registration-related issue, I don't know what the framework is on Android, but I believe there's more secure ways of doing it.

Michael
  • 1,014
  • 1
  • 8
  • 23