Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import android.content.Context
  2. import androidx.room.Room
  3. import androidx.room.RoomDatabase
  4.  
  5. abstract class ExampleDB : RoomDatabase() {
  6.  
  7. companion object {
  8. private var INSTANCE: ExampleDB? = null
  9.  
  10. @JvmStatic
  11. fun get(context : Context): ExampleDB {
  12. if (INSTANCE == null) {
  13. INSTANCE =
  14. Room.databaseBuilder(context, ExampleDB::class.java, "example.db").build()
  15. }
  16. return INSTANCE!!
  17. }
  18.  
  19. @JvmStatic
  20. fun destroyInstance() {
  21. INSTANCE = null
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement