4

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!

Argus9
  • 1,863
  • 4
  • 26
  • 40

3 Answers3

6

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

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • 1
    It seems like ObjectInputStream and ObjectOutputStream may be the solutions I need to store the data internally on the device. The data I'm storing isn't particularly massive so I think I'll forego using Databases right now. I think it's a little over my head anyways. – Argus9 Sep 26 '12 at 00:10
4

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

Community
  • 1
  • 1
Sagar
  • 41
  • 1
  • 2
    If you think these questions are duplicates, consider flagging them as duplicate. Otherwise, you should include some content from the linked page (with attribution) to make this answer stand on its own. – Jeffrey Bosboom Mar 08 '15 at 00:18
0

I'd honestly recommend using a SQLiteDatabase to store them: write functions to map your 3 fields to the database (Calendar would become a NUMERIC, DateFormat would be a String, and the int fields would all be NUMERICs) and to rebuild your object fields from a row in the database. Its a bit heavy up front but will make the inevitable feature expansion much easier.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • Hi, can you provide a link to a tutorial on how to do this? Most of what you just wrote flew right over my head. :) – Argus9 Sep 25 '12 at 21:48
  • The quickest path is (in this case), http://developer.android.com/guide/topics/data/data-storage.html#db which has links to more detailed examples. – Femi Sep 25 '12 at 23:23