Skip to content

Instantly share code, notes, and snippets.

@AkshayChordiya
Last active August 17, 2017 09:36
Show Gist options
  • Save AkshayChordiya/13cb237b3dbda8643bb6b8f70d078cd2 to your computer and use it in GitHub Desktop.
Save AkshayChordiya/13cb237b3dbda8643bb6b8f70d078cd2 to your computer and use it in GitHub Desktop.
Main Activity with ViewModel instance and LiveData observe
class MainActivity : LifecycleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Get the ViewModel instance
val userViewModel = ViewModelProviders.of(this).get(UserViewModel::class.java)
userViewModel.getUsers().observe(this, Observer {
// Update the UI
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment