Divya Motiwala
Divya Motiwala

Reputation: 1669

What is the fastest/preferred way to store static data in android?

I want to store around a thousand strings (like some quotes) and populate a ListView or ListFragment using them. These strings are static and not likely to change once loaded.

It is a read-only data and user should not be allowed to manipulate it.

Should i store them using XML file or a text file, or what could be the best approach?

Upvotes: 7

Views: 3297

Answers (5)

greenapps
greenapps

Reputation: 11214

Just put them in a text file which you store in the assets folder. If you put them line by line you have already your items.

Upvotes: 0

blackjack
blackjack

Reputation: 585

If the data are not going to change in the entire application development why u not going for static final way using with any access modifier as u like and u can use them in your application and as size concern thousand or lakh of String data is not going to effect as we know also String is immutable and can't change throughout the app life and one more thing with declaring as final so reinitialize will not be there but only reusing.Declare all the string in the as the class part so it load when class load i.e. once.If any more thing let me know.

Upvotes: 1

hemantsb
hemantsb

Reputation: 2059

Shared Prefrences is the best way to store small data. You Can take help from this tutorial

Upvotes: 2

quinestor
quinestor

Reputation: 1442

It will never change?

String data type?

Do you have them already when building the app?

Simply save them in Resources, strings; just like you store values like 'appname' You can save one huge string variable separated by line breaks (or commas, colons, etc) , then use java's string utilities or tokenize to get each substring, or anything you seem fit according to the patter it has

Upvotes: 0

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Use Sqlite db thats the efficient and secure way

Upvotes: 2

Related Questions