2

I'm building a home replacement app. I need to store the ArrayList with the apps the user picked to show on the launcher in the internal memory. I mean the array mustn't be deleted when the app is closed.

I'm very close to finishing the app and I don't think I'll work a lot more on Java, I'm not a programmer so I just want the easiest way to do it. How can I store and retrieve an ArrayList in the internal memory?

lisovaccaro
  • 32,502
  • 98
  • 258
  • 410

3 Answers3

5

Use SharedPreferenes to store and retrieve the arrayList..

Check this link..

Save ArrayList to SharedPreferences

Community
  • 1
  • 1
Deepzz
  • 4,573
  • 1
  • 28
  • 52
1

You should store such data as Arraylists in the database and when you relaunch the app just fetch the data from database(SQLite) and display it to the user.

Heres a good tutorial on android SQLite.

Take a look at this link, for all the different data storage mechanisms in android. But for your requirement I would suggest using a db.

Antrromet
  • 15,294
  • 10
  • 60
  • 75
1

The easiest way is to use Java serialsation. It writes the content of an object to a (file-) outputstream. Thats a few lines of code.
a bit better (faster, less bytes, readable by other non java systems) is to uses a custom serialisation, using DataOuputStream. That creates a binary file in the format you define.

AlexWien
  • 28,470
  • 6
  • 53
  • 83