Gabrielle
Gabrielle

Reputation: 4991

Saving arrays of Strings in Android?

I need a sugestion for my app. I need to save in app some arrays of Strings. How can I do this? Which is the best way for doing this?

Thanks in advance...

Upvotes: 1

Views: 612

Answers (4)

Egor
Egor

Reputation: 40228

There are probably two different solutions:

  1. Using SharedPreferences
  2. Using SQLite Database

You can pick one depending on how many strings you want to save. SharedPreferences is commonly used for storing a small amount of data and making it easy to access it. Databases should be used if you want to store a bigger amount of data.

Upvotes: 0

TofferJ
TofferJ

Reputation: 4794

If every String in your array is only a 1 or a 0, then you can build one large String of everything and put in a SharedPreference. When you fetch the saved value all you have to do is parse it character by character to get your 1s and 0s again.

Upvotes: 0

denis.solonenko
denis.solonenko

Reputation: 11775

If the string array is a constant thing, then you can define it in the resources

<string-array name="my_array">
    <item>item1</item>
    <item>item2</item>
</string-array>

You can grab it from the resources later like this

String[] myArray = getResources().getStringArray(R.array.my_array)

Upvotes: 3

Rasel
Rasel

Reputation: 15477

You can use SQLite Database or file in the sdcard to store the strings.It depends on how you need to use them.

Upvotes: 1

Related Questions