How to import Room Persistence Library to an Android project

It’s possible to find the dependencies on the example codelab for the new architecture components. Root : allprojects { repositories { jcenter() maven { url “https://maven.google.com” } } For Room: implementation ‘android.arch.persistence.room:runtime:1.0.0-alpha1’ annotationProcessor ‘android.arch.persistence.room:compiler:1.0.0-alpha1’ For Lifecycle dependencies: implementation ‘android.arch.lifecycle:extensions:1.0.0-alpha1’ annotationProcessor ‘android.arch.lifecycle:compiler:1.0.0-alpha1’ Adding Rxjava2 objects as result for our queries: implementation ‘android.arch.persistence.room:rxjava2:1.0.0-alpha1′ Test migrations: testImplementation’android.arch.persistence.room:testing:1.0.0-alpha1’

Database won’t remove when uninstall the Android Application

in Android 6.0, google added new feature called Auto Backup. when this option is on(default is on), Android system copies almost every directories and files that created by system, and upload it to user’s google drive account. When user reinstalls app, android automatically restore app’s data, no matter how it was installed(via Play store, adb … Read more

Android SQLite Insert or Update

I believe that you are asking how to INSERT new rows or UPDATE your existing rows in one step. While that is possible in a single raw SQL as discussed in this answer, I found that it easier to do this in two steps in Android using SQLiteDatabase.insertWithOnConflict() using CONFLICT_IGNORE for conflictAlgorithm. ContentValues initialValues = … Read more

How to get row count in sqlite using Android?

Using DatabaseUtils.queryNumEntries(): public long getProfilesCount() { SQLiteDatabase db = this.getReadableDatabase(); long count = DatabaseUtils.queryNumEntries(db, TABLE_NAME); db.close(); return count; } or (more inefficiently) public int getProfilesCount() { String countQuery = “SELECT * FROM ” + TABLE_NAME; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); int count = cursor.getCount(); cursor.close(); return count; } In Activity: int … Read more

How to use Room Persistence Library with pre-populated database?

This is how I solved it, and how you can ship your application with a pre-populated database (up to Room v. alpha5) put your SQLite DB database_name.db into the assets/databases folder take the files from this repo and put them in a package called i.e. sqlAsset in your AppDatabase class, modify your Room’s DB creation … Read more