Skip to content

Instantly share code, notes, and snippets.

Last active Oct 28, 2018
What would you like to do?
Article 2, Point 1.1
class BooksFragment: Fragment() {
private lateinit var viewModel: BooksViewModel
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_books, container)
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel = ViewModelProviders.of(this).get(
viewModel.liveData.observe(this, Observer { updateViews(it) }) // Risky: Passing Fragment as LifecycleOwner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment