title: How to get an Instance of ViewModel in activity in 2020/21?
body: <p>I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity. </p>
  
  <p>Most Tutorials and answers here on Stackoverflow suggest using <code>ViewModelProviders.of(...</code>, but this is depreceated. </p>
  
  <p>So according to this question on stackoverflow: <a href="https://stackoverflow.com/questions/53903762/viewmodelproviders-is-deprecated-in-1-1-0,in">ViewModelProviders is deprecated in 1.1.0</a> main activity in onCreate, I do the following (and I could swear I already had it running): <code>mainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);</code></p>
  
  <p>However, I am getting an error telling me, that no suitable constructor has been found. </p>
  
  <p><code>error: no suitable constructor found for ViewModelProvider(MainActivity)</code></p>
  
  <p>Alternatively to make absolutely clear, that the MainActivity shall be the ViewModelStoreOwner, I created a variable 
  <code>ViewModelStoreOwner vmso = this;</code> and put that variable into the constructor like so: 
  <code>mainActivityViewModel = new ViewModelProvider(vmso).get(MainActivityViewModel.class);</code></p>