title: Is it Ok to use singleton instead of ViewModel in case of Jetpack Compose single activity app?
body: <p>There is a similar <a href="https://stackoverflow.com/questions/64617891/where-should-i-be-using-a-singleton-and-where-should-i-be-using-a-viewmodel-for">SO question</a>, 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.</p>
  <p>I've found a way via ViewModel Factory implementation in the Compose <a href="https://developer.android.com/jetpack/compose/interop/compose-in-existing-arch" rel="nofollow noreferrer">documentation</a>, but it looks a bit complicated compared to a singleton approach.</p>
  <p>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.</p>