Donggyu1998

Untitled

Jun 7th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import android.app.Application
  2. import androidx.room.Room
  3. import com.example.myapplication.db.AppDatabase
  4.  
  5. class MyApp : Application() {
  6.  
  7. companion object{
  8. private var context: MyApp? = null
  9.  
  10. fun getAppDb(): AppDatabase? {
  11. return context?.let {
  12. Room.databaseBuilder<AppDatabase>(it, AppDatabase::class.java, "demo.db")
  13. .build()
  14. }
  15. }
  16. }
  17.  
  18. override fun onCreate() {
  19. super.onCreate()
  20. context = this
  21. }
  22.  
  23. }
Add Comment
Please, Sign In to add comment