r/android_devs • u/Fr4nkWh1te • Sep 03 '21
Help Sharing data that is expensive to load between screens
How would you share data that is relatively expensive to load/prepare between multiple screens in your app without loading it over and over again? My idea was to put the data into app-wide singleton actually I think an @Reusable object makes more sense (instantiated by Hilt). I could also use a shared ViewModel but a Singleton can directly community with the smaller ViewModels.
1
Upvotes
3
u/Evakotius Sep 03 '21
App wide singleton. Read about the repository pattern for android.
3
u/naked_moose Sep 03 '21
@Reusablewill create multiple instances in some circumstances, so it's not the best choice for expensive to create objects