title: How to access ViewModel that is registered with MainActivity in Android Jetpack Compose?
body: <p>Android documentation <a href="https://developer.android.com/topic/libraries/architecture/viewmodel" rel="nofollow noreferrer">https://developer.android.com/topic/libraries/architecture/viewmodel</a> details the creation and remember/retrieval of <code>ViewModel</code> instance that is registered with <code>MainActivity</code>.</p>
  <p>My question is - how can I access this <code>viewModel</code> instant from other <code>ViewModel</code> or from <code>@Compose</code> function?</p>
  <p>I have tried code</p>
  <pre><code>private val sessionViewModel: SessionViewModel by viewModels()
  </code></pre>
  <p>both in my classes descending from <code>ViewModel</code> and in <code>@Composable</code> functions, but <code>viewModels()</code> function is not available there.</p>
  <p>He is how I have done registration:</p>
  <pre><code>class MainActivity : AppCompatActivity() {
      //...
      val sessionViewModel: SessionViewModel by viewModels&lt;SessionViewModel&gt;()
  }
  </code></pre>