First time posting a question and I'm a coding noob so sorry if I do something wrong.
I check around and found one answer which is somewhat similar to my question: When / How to Create / Destroy Room Database
However I am not using dagger, nor do I know how to use it.
I wanted to ask when should you build your room database instance? Suppose my app uses the database throughout, should I build it in the OnCreate of the Main Activity? Or should I only build it once the users tries to access some functionality that requires it?
This is the code in question:
instance = Room.databaseBuilder(context.getApplicationContext(), MovieDatabase.class, DB_NAME).build();
So basically when is the best time to run the above code?
Please let me know if this question doesn't make sense.
Your Database Instance will be built as Singleton and you can access it anywhere as it will be created only once.
Please follow this codelab tutorial to get a clear vision of using Room
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With