3

I have 2 data sets

String[] wordsArray;
Queue<String> wordsQueue;

They store the same data, around 500 strings each, 1-3 words per string. I need to save one of them to SharedPreference. What is the best (fastest) way to do it?

Now I just use

Set<String> mySet = new HashSet<String>(wordsQueue);
edit.putStringSet("Words", mySet);

But it works slower than I want.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
Gaijin
  • 61
  • 8

1 Answers1

5

Use apply() instead of commit() which will save the preference in a background thread (i.e. asynchronous).

Set<String> mySet = new HashSet<String>(wordsQueue);
edit.putStringSet("Words", mySet).apply();

For saving the array of String in SharedPreference you might consider doing something like this stated in this answer.

Community
  • 1
  • 1
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98