Duplicate Data Issue Android Sqlite
Solution 1:
If I get your problem right, you could use a helper class and extend SQLiteOpenHelper.
In the onCreate method you can insert the needed data. This method is called only once.
Hope this helps.
Solution 2:
You should have a SQLiteOpenHelper
class which contains some methods for database management and lifecycle like
onCreate(SQLiteDatabase db) // Called when the database is created for the first time.onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) //Called when the database needs to be downgraded.onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) // Called when the database needs to be upgraded.
And other ones, you can have a look here: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
Following this tutorial should keep you on the good path about using this helper: http://developer.android.com/training/basics/data-storage/databases.html
My advice is to create some Querys like the ones that will populate and execute them after the creation of the Tables which should be there too. This way, your app will only make those inserts the first time, and keep them even if you update your database (if you don't state something else on the onUpgrade() method).
This should fix your problem.
Post a Comment for "Duplicate Data Issue Android Sqlite"