0

I am trying to create an app that will give users the option to create a new project or select an existing project. These projects will contain a name (title) and a group of images they are allowed to take. Basically an album. The only way I can think of doing this is by writing to a file the name of the project and a bunch of id's for every picture they had selected for that project. Store this in an array and reload it every time they start the app. Is this a good way to go about doing this or is there a more eloquent way of doing this?

Jaiesh_bhai
  • 1,778
  • 8
  • 26
  • 41

2 Answers2

1

Viperbone's answer is good. May I encourage you to add a little extra to it?

Create a class which represents your projects. Make this class serializable. In this class, create "save" and "load" methods. Initially, your save method may use SQLite but, in the future, there might be many reasons why you want to change this (save to Dropbox? Export? - hence the serialization).

If you isolate the way in which you save your projects, you can change the underlying storage mechanism to whatever you want, in theory without having to change the rest of the code.

You could go a step further and have the save/load methods in a separate class with an Interface you define. In this way, you could even have multiple save methods and add new ones with little effort simply by adding new classes which use the same interface.

Building in this kind of flexibility often pays back the initial investment many times as your app evolves.

Simon
  • 14,407
  • 8
  • 46
  • 61
0

you could use a sqlite database to store the projects in a table and in another table store the list of images and in a third table a list which image belongs to which project(s).

You could use the following tables:

Projects table


ID - AutoInt

Title - varchar(255)


Images table


ID - AutoInt

ImageID - Int


Project Image relation table


ID - AutoInt

ProjectID - Int

ImageID - Int


Have a look at this sqlite database tutorial: http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

or this: http://android-er.blogspot.ch/2011/06/simple-example-using-androids-sqlite_02.html

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
  • thanks this was helpful. It does make sense to do it this way. Would you happen to know how with the Image id i would retrieve images? Sorry if this is a stupid question. – Jaiesh_bhai Sep 16 '12 at 19:14
  • Where do you have stored your images? if they are in the drawable folder(s) you can just in your main activity write this: this.getResources().getDrawable(R.drawable.imagename); – Bruno Bieri Sep 17 '12 at 05:21
  • I am allowing them to be chosen from the Gallery/and or just using the camera application to take the the picture (which i assume gets saved to gallery as well). – Jaiesh_bhai Sep 18 '12 at 16:57
  • I think here is an example how you can the user choose an image from the gallery. Then you have to store the path of the image in your "project": http://stackoverflow.com/questions/2169649/open-an-image-in-androids-built-in-gallery-app-programmatically – Bruno Bieri Sep 19 '12 at 05:19