architecture-components-samples icon indicating copy to clipboard operation
architecture-components-samples copied to clipboard

BasicSample uses singletons poorly, ignoring parameters

Open manger opened this issue 5 years ago • 0 comments

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()

manger avatar Feb 24 '20 22:02 manger