How to add multiple numbers in Sharedpreferences and always keep the instance of SharedPreferences?

1

I needed to add a data in Sharedpreferences and it stored all data, not "zeroing" my data anymore. I'm using editor.putStringSet("data", dado); to store my data, I needed to keep this data forever. Is it possible to do that? Thank you in advance!

    
asked by anonymous 24.09.2015 / 17:19

1 answer

1

To keep the old data you must enter a new key. Here is an example of generating a key based on the GUID, where this key will never be repeated.

Amount: import java.util.UUID;

e Do the following:

UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString();
editor.putStringSet(randomUUIDString , dado);

I hope I have helped.

But I recommend you create a SQLITE database, so you have control over your information so you can easily search and change data quickly.

See my answer to this question Insert sqlite into android application . This will definitely help you implement a SQLITE bank on android.

    
24.09.2015 / 18:32