architecture-components-samples
architecture-components-samples copied to clipboard
BasicSample uses singletons poorly, ignoring parameters
DataRepository.getInstance(AppDatabase database) returns a singleton. But that means the database parameter is ignored from calls other than the first. Subsequent calls are returned a DataRepository for a different database!
AppDatabase.getInstance(Context context, AppExecutors executors) has the same problem. It also returns a singleton, hence ignores the parameters to subsequent calls.
The solutions is easy. Implement the singleton functionality in the BasicApp class. BasicApp.getDatabase() BasicApp.getRepository()