Skip to content

Instantly share code, notes, and snippets.

Last active May 29, 2020
What would you like to do?
BaseActivity for the demo of template creation.
abstract class BaseActivity<D : ViewDataBinding, V : BaseViewModel> : AppCompatActivity(){
protected abstract val layoutId: Int
protected abstract val viewModelClass: Class<V>
internal val viewModel:V by lazy { ViewModelProvider(this).get(viewModelClass) }
internal lateinit var binding: D
private set
override fun onCreate(savedInstanceState: Bundle?) {
binding = DataBindingUtil.setContentView(this, layoutId)
binding.setVariable(BR.viewModel, viewModel)
binding.lifecycleOwner = this
open fun onCreated(savedInstanceState: Bundle?, extras: Bundle?) { }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
viewModel.onActivityResult(requestCode, resultCode, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment