how to bulk insert in sqlite in android

Use a transaction to insert all the rows — NOT one row per transaction. SQLiteDatabase db = … db.beginTransaction(); try { // do ALL your inserts here db.setTransactionSuccessful() } finally { db.endTransaction(); } EDIT public void add_cities(List<Cities> list) { SQLiteDatabase db = this.getWritableDatabase(); db.beginTransaction(); try { ContentValues values = new ContentValues(); for (Cities city : … Read more

Why can’t I use Resources.getSystem() without a Runtime error?

According to Android documentation, Resources.getSystem() only provides system-level resources, not application-level ones (like the resources inside your strings.xml file). http://developer.android.com/reference/android/content/res/Resources.html#getSystem() Try using the application’s context if you really want to retrieve your strings this way, or take my suggestion in the comment to your question.

Confusion: How does SQLiteOpenHelper onUpgrade() behave? And together with import of an old database backup?

What’s the correct way of handling database upgrades of a live app, so the user doesn’t lose his data? Do you have to check all possible (old) versions in the onUpgrade() method and execute different alter table statements based on that version? By and large, yes. A common approach to this is to do pair-wise … Read more

Android SQLite Example [closed]

Sqlite helper class helps us to manage database creation and version management. SQLiteOpenHelper takes care of all database management activities. To use it, 1.Override onCreate(), onUpgrade() methods of SQLiteOpenHelper. Optionally override onOpen() method. 2.Use this subclass to create either a readable or writable database and use the SQLiteDatabase’s four API methods insert(), execSQL(), update(), delete() … Read more

When does SQLiteOpenHelper onCreate() / onUpgrade() run?

SQLiteOpenHelper onCreate() and onUpgrade() callbacks are invoked when the database is actually opened, for example by a call to getWritableDatabase(). The database is not opened when the database helper object itself is created. SQLiteOpenHelper versions the database files. The version number is the int argument passed to the constructor. In the database file, the version … Read more