0

I am developing a notepad app which can store simple text files and checklists. Currently I maintain a separate file (say info.txt) that maintains information about whether a given file is a simple text file or a checklist and based on that I render my UI (for either listing all files or opening a file) to show that file in my app. However I am not very happy with this approach because is slow and does not appear to scale well.

Is there a better way to add "metadata" (e.g. if it is a simple text or cheklist, tags, etc) about a file in android?

Any help will be greatly appreciated

user3268403
  • 203
  • 2
  • 14
  • Have you looked into Android's [SharedPreferences](http://developer.android.com/reference/android/content/SharedPreferences.html)? There is a good question [here](http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) about it as well. – Spaceman Spiff Oct 03 '14 at 19:56
  • Yes, Ian. SharedPreferences has crossed my mind. I wonder if that is the best approach, especially if I want to start adding "tags" to files. Not sure how searching will scale. will it work well if i want to search all files with a certain tag. There is also SQL-lite (I have never used this before) ... Dont know how that works – user3268403 Oct 03 '14 at 20:02
  • SQL-lite would probably be better if you are going to be running queries on the data as you mention finding files with a certain tag, although it is a little more difficult to set up than the shared prefences in my opinion. SQL-lite is going to be far more flexible as well in case you start adding features – Spaceman Spiff Oct 03 '14 at 22:44
  • Thanks Ian. If you can summarize it as an answer, I can accept it! – user3268403 Oct 07 '14 at 21:32

1 Answers1

0

There are several ways of storing persistent data in Android.

The way you are currently doing it is through the device storage, and you are quite right it would probably not scale well in addition to being directly accessible to the user meaning they could edit or delete your metadata.

Using SharedPreferences would be one way of storing the metadata which has the advantage of being completely hidden from the user, as well as being relatively easy to set up. The main disadvantages I can see are that it may not scale well if a user has a large number of files, and it is much more difficult to retrieve files with certain criteria, a certain tag for instance, as you mention in the comments.

The best way to store data that will scale well, be persistent, and let you run queries on the data would be an on device SQLite database. SQLite will usually have more overhead in terms of setup time, but is far more robust and featured than any of the other options besides perhaps network based storage, which based on the information you have given is probably not something you are interested in. Based on your problem the SQLite database is probably the way to go and has the bonus of being expandable in case you ever decide to add more information, or even store the files in the SQLite database.

Spaceman Spiff
  • 934
  • 1
  • 14
  • 32