I'm having problems in saving data in phones local SQL database file. I'm using Cars.db file where I have two tables, car and favourites. When user selects to add car to favourites it adds the car to favourites but when I close the app and open it back again the app doesn't have any data in favourites table.
The code works to see list of cars in favourites and I can select any car from list to view details on the car as well. I have MyDBHandler class object initialized in main activity as static object and using that objects reference to insert, and query data from Cars.db file.
public class MyDbHandler extends SQLiteOpenHelper {
private static final String DB_Name = "Cars.db";
private static final String TABLE_Cars = "Cars";
private static final String Table_Favourite = "Favourite_Cars";
private static final int DATABASE_VERSION = 1;
private SQLiteDatabase database;
public MyDbHandler(Context context) {
super(context, DB_Name, null, DATABASE_VERSION);
try {
copyDataBase(context); //Copies databse file to phones data/data/... folder
database = this.getWritableDatabase();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aucun commentaire:
Enregistrer un commentaire