views:

686

answers:

3

I'm looking for something like the keychain on the iPhone, but for Android development.
Something that gives me the possibility to save small key-value pairs, that are persistent and unchanged even if the user reinstalls the application.

Is there something like that? Can I use the standard preferences that way?

I would like to achieve a behavior in a way it works with games on a PC writing the save games to another folder so that after delete and later reinstall they are not lost.

Edit

The bounty run out without somebody mentioning the accountManager. I just stumbled over it. Wouldn't that be a method to achieve the behaviour described by me?

A: 

Yes. Preferences are persistant and will survive a normal application upgrade.

Michael Cramer
Preferences will not survive a re-install though.
dweebo
Of course...if you uninstall an app it will remove all associated data. Doing otherwise would require a loose definition of "uninstall".
Michael Cramer
That is bad... Sometimes you want some things to be able to stay, like savegames, account data etc. The things that also don't get uninstalled if you uninstall desktop applications
Janusz
Although I disagree with the idea that you would retain data when the user explicitly uninstalls an app, you could write to the SD card explicitly.
Michael Cramer
@Janusz you have to remember that you are working on a phone, not a desktop computer. People generally expect that mobile phone applications are more simple than desktop applications, and don't want to worry about cleaning up files your application hides on their device
mvid
I know but the applications requires to identify the user. But I don't won't them to remeber and create an account it would be easier if I could create an account and save it to the keychain
Janusz
+1  A: 

Since Android & iPhone-like phones will normally run with a data plan, I would suggest that you save your key-value pairs into a centralized server. When the app goes through the uninstall, followed by an install process, just resync it with your server.

Jacques René Mesrine
I would like to that but I somehow have to identify the user. I don't want to make the user choose a user name but choose a user id automatically and then use that for resync but this id is also lost after an uninstall...
Janusz
you can identify a phone by IMEI, as Ravi Vyas mentioned. It is most likely a safe assumption that there is a one to one relationship between a phone and a user.
mvid
sure except for all the people who like to have the newest phone on the block and sell the old one on ebay because they are not locked in to some strange plans
Janusz
+3  A: 

You you use storage on the SD card like Michael Cramer stated ( Let the user know you are storing data :-) ). The data on the SD card is not deleted when the app is removed.

You could on the other hand use a server which stores all the details which can be downloaded as and when required and instead of using a user name use the IMEI of the phone which is unique. That way even if the user reinstalls the OS he will still be able to refetch the settings.

for getting the IMEI you may refer : http://stackoverflow.com/questions/1972381/how-to-programmatically-get-the-devices-imei-esn-in-android

Ravi Vyas