Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lose some values using getStringSet and putStringSet

I found out that some values had been stored to Set got lost after restarting the application. Why? Is this an Android API bug? Somebody advised to store strings in a database. I haven't tested it yet, but I think this advice is a solution of the problem. What about getStringSet and putStringSet?

like image 280
Maksim Dmitriev Avatar asked Dec 26 '22 06:12

Maksim Dmitriev


1 Answers

From my understanding, it's a bug. The problem is when you try to store a set, Android compares the modified set that you are trying to save with the current one stored in the SharedPreferences. And when they are the same object (having the same reference), the new one is ignored.

A work around is to create a new copy of the set before storing it.

Here is the details and the issue is submitted at https://code.google.com/p/android/issues/detail?id=27801.

like image 80
pt2121 Avatar answered Jan 08 '23 07:01

pt2121