Storing short strings and numeric values ​​in resources in Android

I want to have some static numeric and text values ​​as an application resource. For example, my data is as follows:

Levels 5 First_Level 500 60 1 Second_Level 500 80 1 Third_Level 200 60 1 Fourth_Level 130 30 2 Final_Level 100 30 3
... and another 300 lines...

The format and order of the data are predefined and guaranteed to be valid.

I could read it using java.util.Scanner, but it is very slow in Android, reading a 10 kilobyte file takes minutes. It is slow due to matching the regex-based pattern inside (when I tracked it).

How could you suggest saving them?

+3
source share
3 answers

You can store it in an object array, this object just implements Serializable.

ObjectOutputStream.writeObject(list), readObject.

+1

resources/raw (, CSV TSV) Resources.openRawResource InputStream. .

+1

Android :

  • , .. string/integer. <string name="mystring">My String</string> <integer name="myint">123</integer> R.string.mystring R.integer.myint. , .
  • xml res/xml. , binary-xml, , , .. . Resources#getXml, , , getAttributeIntValue("attribute_name"), int .
  • Parcel -ed. android.os.Parcel - . Parcelable , .
+1

Source: https://habr.com/ru/post/1728011/


All Articles