I have created a database that has a table of food items and their corresponding calorie values. The full detail of the table is as follows
Food Item Food Amount Unit of Amount Calorie Value of Food Amount
"Almonds, shelled", 1, "Item", 11
"Apple", 1, "Item", 80
"Apple juice", 240, "ml", 115 -------> 115 Cal / 240 ml
"Barley", 113.4, "g", 390
To create the database, I have created a class called DBAdapter. The following is the code for it:
So to create the database, I just create a new instance of DBAdapter and use insertTitle() method to insert rows into the table like so:
I put this code inside the onCreate() method of my activity class
So this way every time the onCreate method runs, it opens a database, inserts items into the table and then closes when the android application closes. I am looking for a way to update my code so that the table data can be saved permenantly on the device (ie data is saved somewhere when the application closes). This way the onCreate() method can just load the data instead of use open database, use insertTitle() method every time to populate the table. I am not using a specific device. I am using an emulator to run my application right now.
I am thinking of using SQLLite.create() method to store data permenantly, but I am not sure how to update my code. Any Ideas? I would like a specific answer with code if possible please.