1

I have an array integer in android studio like this { 0 , 0 , 0 , 1 , 1 , 0 , 1} how can I store and recall it in shared preferences

AshkanAbd
  • 27
  • 10

2 Answers2

0

There is no way you can store an array as it is. Either you can convert it to JSON String and store it as a string. Or you can store each element of the array individually with an ID like this.

Community
  • 1
  • 1
priyank
  • 2,651
  • 4
  • 24
  • 36
0

Build a string out of it. Preferably using StringBuilder.

And, when reading, just split() on commas and then user Integer.parseInt() on all elements of the array.

Should be faster than the json route and does not require any extra dependency.

KarolDepka
  • 8,318
  • 10
  • 45
  • 58