New2Droid
New2Droid

Reputation: 31

Save a dictionary for later reading in android java

This is my first android app and first time using java so please be patient with me.

In my app in the MainActivity.java i fetch data from a server and form it into a dictionary which i call listings. I need to access listings in my next activity webResults.java, I would preferably want to save it to Local Storage so the user cannot read it, and i can access it a few different times. I've tried using the FileOutputStream doing the following:

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

But that is only a string and not a dictionary.

How can I save a dictionary for later retrieval in my app?

Upvotes: 1

Views: 264

Answers (1)

Simulant
Simulant

Reputation: 20142

The best data storage option for Android Apps is the SQLite-Database build in to Android. It is private to the App, so every app has it own database and the User can not access the database in the file structure.

Please read the linked google tutorial on how to read from and write to theSQLite Database. There are two demo projects linked below the article with example code on how to read and write.

Upvotes: 4

Related Questions