开发者

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 i开发者_开发问答n advance...


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)


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜