Last active
March 30, 2021 05:21
-
-
Save mutairibassam/c6caf87bca2bd7d5e90ffba827b1d9ec to your computer and use it in GitHub Desktop.
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
public abstract TodoDao todoDao(); | |
//Create the WordRoomDatabase as a singleton to prevent having multiple instances of the database opened | |
//at the same time, which would be a bad thing | |
private static TodoDatabase INSTANCE; | |
public static final String DATABASE_NAME = "TASK_DATABASE"; | |
// singlton: to make sure there is no more than one copy | |
// @synchronized one thread only can deal with this database | |
public static synchronized TodoDatabase getInstance(Context context) { | |
if(INSTANCE == null) { | |
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), | |
TodoDatabase.class, DATABASE_NAME) | |
.fallbackToDestructiveMigration() | |
.build(); | |
} | |
return INSTANCE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment