Karol Trawa
Karol Trawa

Reputation: 21

Storing data with multiple values pernamently in Java Android Studio

I need to store 1 key with 4 values (String)
Something like this:
(value1, value2, value3, value4) <- first key
(value1, value2, value3, value4) <- second key
...

I want to read data to variables
var1 = key1:value1
var2 = key1:value2
...

And! At the end i need to edit one value pernamently, so when i restart the app value dont reset.

key1:value1 = "new value"
...

How i can achieve this?

I have tried to make array, but they are hard coded. I think reading - writing to file/resource is the best way

Upvotes: 0

Views: 56

Answers (1)

Paolino L Angeletti
Paolino L Angeletti

Reputation: 184

in android you can store permanent data in 2 ways:

  1. implementing a local database in SQLite (see this link https://www.geeksforgeeks.org/how-to-create-and-add-data-to-sqlite-database-in-android/)
  2. shared preferences, with it you can store "key -> value" informations (link: https://developer.android.com/training/data-storage/shared-preferences).

If I have well understood your problem, you need a database for your request. writing and reading from files, if you permits me, is a tad ugly.

Upvotes: 1

Related Questions