At a tutorial on using SQLite databases. Within this tutorial, it suggested to use a separate class for each new table you create for a database for good practise. I followed this with relative ease. However, I am now having issues with entering data into the database as I am unsure of where to place “insertMethod ()” as well as how to call it into the activity. I have checked multiple tutorials but they all showed examples using a single table in the database class which I had tried previously and worked fine.
Any help would be much appreciated.
I believe best practice would tell you to place your insert method for a given table in a DAO (Data Access Object). Now that means that there should actually be two classes for any given table from my experience. There should also be a POJO that matches your table model used for sharing data between the database and your code. Maybe this is where your confusion is. I believe this is all laid out quite nicely by Lars Vogal here. Now this is all over simplified because your DAO’s do not have to have a one to one relationship to a table and Model Class, but for your purposes this may be fine. I wouldn’t get caught up in tutorials that use one table or more than one. You can use the same methodology for one table on the other tables. To answer your question of how to call your dao query methods in an Activity you should use AsyncTask. I believe that is covered in the article also. Hope this helps.