Created
June 17, 2019 18:18
-
-
Save DanishAmjad12/17a53c2a64489d714de1aa5e72af5bca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.roomdatabase | |
import android.annotation.SuppressLint | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import android.util.Log | |
import androidx.room.Room | |
class MainActivity : AppCompatActivity() { | |
@SuppressLint("LogConditional") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
var db = Room.databaseBuilder(applicationContext, AppDb::class.java, "BookDB").build() | |
//Insert Case | |
val thread = Thread { | |
var bookEntity = BookEntity() | |
bookEntity.bookId = 1 | |
bookEntity.bookName = "Kotlin for Android Developer" | |
db.bookDao().saveBooks(bookEntity) | |
//fetch Records | |
db.bookDao().getAllBooks().forEach() | |
{ | |
Log.i("Fetch Records", "Id: : ${it.bookId}") | |
Log.i("Fetch Records", "Name: : ${it.bookName}") | |
} | |
} | |
thread.start() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment