package jackall.devrealm.activity import android.arch.lifecycle.ViewModelProviders import android.databinding.DataBindingUtil import android.os.Bundle import android.support.v7.app.AppCompatActivity import jackall.devrealm.R import jackall.devrealm.databinding.ActivityMainBinding import jackall.devrealm.viewmodel.MainViewModel class MainActivity : AppCompatActivity() { val binding by lazy { DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main) } val mainViewModel by lazy { ViewModelProviders.of(this, MainViewModel.Factory()).get(MainViewModel::class.java) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding.mainViewModel = mainViewModel lifecycle.addObserver(mainViewModel) } }