Created
November 13, 2019 07:53
-
-
Save ma-za-kpe/d17e86827be09e853a46a5384c353cb6 to your computer and use it in GitHub Desktop.
Can anyone please explain this method to my(as if explaining to a dummy)
This file contains 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
// Annotates class to be a Room Database with a table (entity) of the Word class | |
@Database(entities = arrayOf(Word::class), version = 1, exportSchema = false) | |
public abstract class WordRoomDatabase : RoomDatabase() { | |
abstract fun wordDao(): WordDao | |
companion object { | |
// Singleton prevents multiple instances of database opening at the | |
// same time. | |
@Volatile | |
private var INSTANCE: WordRoomDatabase? = null | |
fun getDatabase(context: Context): WordRoomDatabase { | |
val tempInstance = INSTANCE | |
if (tempInstance != null) { | |
return tempInstance | |
} | |
synchronized(this) { | |
val instance = Room.databaseBuilder( | |
context.applicationContext, | |
WordRoomDatabase::class.java, | |
"word_database" | |
).build() | |
INSTANCE = instance | |
return instance | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment