1

I'm in the early stages of a note-taking application for android and I'm hoping that somebody can point me to a nice solution for storing the note data.

Ideally, I'm looking to have a solution where:

  • Each note document is a separate file (for dropbox syncing)
  • A note can be composed of multiple pages
  • Note pages can have binary data (such as images)
  • A single page can be loaded without having to parse the entire document into memory
  • Thread-safety: Multiple reads/writes can occur at the same time.

XML is out (at least for the entire file), since I don't have a good way to extract a single page at a time. I considered using zip files, but (especially when compressed) I think they'd be stuck loading the entire file as well.

It seems like there should be a Java library out there that does this, but my google-fu is failing me. The only other alternative I can think of is to make a separate sqlite database for every note.

Does anybody know of a good solution to this problem? Thanks!

zpinter
  • 2,232
  • 2
  • 23
  • 29

2 Answers2

2

Seems like a relational database would work here. You just need to play around with the schema a little.

Maybe make a Pages table with each page including, say, a field for the document it belongs to and a field for its order in the document. Pages could also have a field for binary data, which might be contained in another table. If the document itself has additional data, maybe you have a table for documents too.

I haven't used SQLite transactions on an Android device, but it seems like that would be a good way to address thread safety.

Brian Cooley
  • 11,622
  • 4
  • 40
  • 39
1

I would recommend using SQLite to store the documents. Ultimately, it'll be easier than trying to deal with file I/O every time you access the note. Then, when somebody wants to upload to dropbox, you generate the file on the fly and upload it. It would make sense to have a Notes table and a pages table, at least. That way you can load each page individually and a note is just a collection of pages anyway. Additionally, you can store images as BLOBS in the database for a particular page. Basically, if you only want one type of content per page, then you would have, in the pages table, something like an id column and a content column. Alternatively, if you wanted to support something that is more complex such as multiple types of content then you would need to make your pages a collection of something else, like "entities."

IMO, a relational database is going to be the easiest way to accomplish your requirement of reading from particular pages without having to load the entire file.

Chris Thompson
  • 35,167
  • 12
  • 80
  • 109