This website or its third-party tools use cookies which are necessary to its functioning and required to improve your experience. By clicking the consent button, you agree to allow the site to use, collect and/or store cookies.
Please click the consent button to view this website.
I accept
Deny cookies Go Back

Mobile app tutorials

  • Home
  • About
  • Contact
  • Login
You are here: Home / Kotlin Fragments / Kotlin sharing data between fragments using ViewModel

December 13, 2017 by nigel

Kotlin sharing data between fragments using ViewModel





The Kotlin sharing data between fragments using ViewModel android development tutorial describes using the ViewModel to share data between Android fragments

This Kotlin on Android tutorial follows directly on from the passing data from Android activity to Android fragment tutorial.

In the Kotlin on Android ViewModel tutorial the code for sharing the data in the previous tutorial will first be removed.

A ViewModel will be created then be created with a Uri member.

If you are new to Android and/or Kotlin I recommend the Kotlin Fragments series to be done prior to this Kotlin on Android tutorial.

The key concepts this Kotlin on Android tutorial will cover are

  1. Creating the Android ViewModel
  2. Using Kotlin lazy delegate for ViewModel instance
  3. Setting and getting ViewModel members in Kotlin
  4. Calling an Android fragment from inside a fragment

Episodes

  1. Fragment Interface
  2. Fragment Arguments
  3. ViewModel
To get access to the source code and code descriptions please fill out the form below to complete your free membership:
An account with your username and/or email address has been created. Log in here to access your products or complete a purchase. [Note: an account will be created even if your initial transaction failed at checkout. If this happened to you, simply log in and attempt your transaction again.]










Conclusion

In the Kotlin sharing data between fragments using ViewModel android development tutorial, we described how to use the Android ViewModel to share data between Android fragments.

Compared to the solutions from the two previous episodes, the Android ViewModel provides a much cleaner and simpler solution.

All that is required to implement the ViewModel. Then inside each fragment, implement a ViewModel instance. Which can then be called when required.

Print Friendly

Filed Under: Kotlin Fragments Tagged With: Android, Android Development Tutorials, Android Fragment, Kotlin, Kotlin Fragment Viewmodel, Pass Data, Sharing Data, Viewmodel

  • Facebook
  • Google+
  • Twitter
  • YouTube




Recent Forum Topics

  • Kotlin Fragments
  • Kotlin Camera2 API
  • HTTP Image Libraries

Recent Posts

  • Installing and running flutter
  • Kotlin Camera2 API MediaRecorder
  • Flutter IntelliJ Tips for Beginners
  • Migrating Fragments to Jetpack Navigation
  • Flutter TabBar

Recent Posts

  • Installing and running flutter
  • Kotlin Camera2 API MediaRecorder
  • Flutter IntelliJ Tips for Beginners
  • Migrating Fragments to Jetpack Navigation
  • Flutter TabBar

Search Form

  • Facebook
  • GitHub
  • Google+
  • Twitter
  • YouTube

© 2021 - WWW.MOBAPPTUTS.COM