Is it Ok to use singleton instead of ViewModel in case of Jetpack Compose single activity app?

Viewed 536

There is a similar SO question, but I would like to ask specifically regarding Jetpack Compose. I have a single activity application that has a single ViewModel instance used in all composables. It works well, but now I need to add a Room db instance as a constructor parameter to it.

I've found a way via ViewModel Factory implementation in the Compose documentation, but it looks a bit complicated compared to a singleton approach.

What actually is wrong with using a singleton instead of ViewModel for a single activity Compose app? It looks perfectly fine to have a singleton instance for the app lifetime. Why do we need to bother about the Activity lifecycle in this scenario? As a benefit I'll get rid of ViewModel dependency and most probably reduce apk size.

0 Answers
Related