Activity override fun onBackPressed() { supportFragmentManager.fragments.reversed().forEach { if (it.isVisible && it is OnBackPressedListener) { if (it.onBackPressed()) return } } super.onBackPressed() }
by lazy { ViewModelProviders.of(this).get(UserDetailViewModel::class.java) } // in Fragment private val activityViewModel: UserDetailViewModel by lazy { ViewModelProviders.of(requireActivity()).get(UserDetailViewModel::class.java) } // in Fragment in Fragment private val parenttViewModel: UserDetailViewModel by lazy { ViewModelProviders.of(requireParentFragment()) .get(UserDetailViewModel::class.java) }
by viewModels() // in Fragment private val activityViewModel: UserDetailViewModel by activityViewModels() // in Fragment in Fragment private val viewModel: UserDetailViewModel by viewModels({ requireParentFragment() })