Storing data with multiple values pernamently in Java Android Studio

43 views Asked by At

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

1

There are 1 answers

0
Paolino L Angeletti On

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.