Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Application
- import androidx.room.Room
- import com.example.myapplication.db.AppDatabase
- class MyApp : Application() {
- companion object{
- private var context: MyApp? = null
- fun getAppDb(): AppDatabase? {
- return context?.let {
- Room.databaseBuilder<AppDatabase>(it, AppDatabase::class.java, "demo.db")
- .build()
- }
- }
- }
- override fun onCreate() {
- super.onCreate()
- context = this
- }
- }
Add Comment
Please, Sign In to add comment