Skip to content

Instantly share code, notes, and snippets.

@rachitmishra
Last active November 7, 2017 19:18
Show Gist options
  • Save rachitmishra/5c8b45ee706472ab17711f96fbb4c840 to your computer and use it in GitHub Desktop.
Save rachitmishra/5c8b45ee706472ab17711f96fbb4c840 to your computer and use it in GitHub Desktop.
dagger-android-activity
/**
* An activity with a `HomeViewModel` dependency
*/
class HomeActivity : AppCompatActivity() {
@Inject
lateinit var homeViewModel: HomeViewModel // Requesting the dependency
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) // This line will initialise our dependency, and has to be called before `super`
super.onCreate(savedInstanceState)
val activityHomeBinding = setDataBindingView<ActivityHomeBinding>(R.layout.activity_home)
activityHomeBinding.viewModel = homeViewModel
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment