Skip to content

Instantly share code, notes, and snippets.

@pedromassango
Created October 3, 2018 10:21
Show Gist options
  • Save pedromassango/7abdcb60e906981e52df6bf6632b826d to your computer and use it in GitHub Desktop.
Save pedromassango/7abdcb60e906981e52df6bf6632b826d to your computer and use it in GitHub Desktop.
Usage of an class injected by Koin in an Activity
class MainActivity : AppCompatActivity() {
// we get our viewModel from Koin
private val mainViewModel: MainViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
mainViewModel.loadData()?.observe(this, Observer{
// show message coming from ViewModel -> Repository
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment