Created
March 21, 2020 07:33
-
-
Save wfng92/f43e62639d22570866c66a60d8d7448c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import android.content.Context; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import androidx.room.Database; | |
import androidx.room.Room; | |
import androidx.room.RoomDatabase; | |
@Database(entities = {User.class}, version = 1) | |
public abstract class AppDatabase extends RoomDatabase { | |
public abstract UserDao userDao(); | |
private static volatile AppDatabase INSTANCE; | |
private static final int NUMBER_OF_THREADS = 1; | |
static final ExecutorService databaseWriteExecutor = | |
Executors.newFixedThreadPool(NUMBER_OF_THREADS); | |
static AppDatabase getDatabase(final Context context) { | |
if (INSTANCE == null) { | |
synchronized (AppDatabase.class) { | |
if (INSTANCE == null) { | |
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), | |
AppDatabase.class, "user_database") | |
.build(); | |
} | |
} | |
} | |
return INSTANCE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment