Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Way to Store Custom Objects to Internal Storage in Android?

Tags:

android

I have a custom object, "TimeSheet", which itself contains Calendar, DateFormat, and int fields. The App is designed to use several of these objects, so I'm planning on storing them in a List as they're created and I'd like the App to be able to save these objects to internal storage when the App closes and reload them when it opens.

I'm still something of a novice when it comes to Android development (I've only published one App so far), so I'm not entirely sure of the best way to go about this. I'm guessing an ObjectInputStream and its Output counterpart are probably the best options, but I'm not entirely sure. I'm completely willing to change my design strategy to store a collection of these TimeSheet objects in the easiest way possible.

Can anyone recommend a good direction to go from here, and if possible, provide brief, simple examples?

Thanks!

like image 502
Argus9 Avatar asked Dec 27 '22 17:12

Argus9


2 Answers

There is no single right answer for something like this. A lot of it depends on the amount of data that you are storing. If you don't have much data, used SharedPreferences, if you have lots of data and it is complex, use a database. I wouldn't use a database if you don't have much data. You want to keep things as simple as possible and adding a database can complicate things. Here is a link that talks about the different options. Check it out. Hope it helps:

http://developer.android.com/guide/topics/data/data-storage.html

like image 186
BlackHatSamurai Avatar answered May 23 '23 20:05

BlackHatSamurai


There are 2 ways to do this

  1. Save it in a SQLite database..
  2. Save the objects in a json format in a file

See this discussion

like image 28
Sagar Avatar answered May 23 '23 20:05

Sagar