Last active
November 7, 2019 13:39
-
-
Save behrends/1549b198884da2a52d681ca8128a8dad 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.example.roomexample | |
import android.content.Context | |
import androidx.room.Database | |
import androidx.room.Room | |
import androidx.room.RoomDatabase | |
@Database(entities = [Person::class], version = 1) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun personDao(): PersonDao | |
companion object { | |
@Volatile private var instance: AppDatabase? = null | |
@Synchronized | |
fun getDatabase(context: Context): AppDatabase { | |
if(instance == null) { | |
instance = Room.databaseBuilder( | |
context.applicationContext, | |
AppDatabase::class.java, | |
"people.db" | |
).build() | |
} | |
return instance!! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment