Created
October 3, 2018 10:21
-
-
Save pedromassango/7abdcb60e906981e52df6bf6632b826d to your computer and use it in GitHub Desktop.
Usage of an class injected by Koin in an Activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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