Android Jetpack: LiveData

author Android Developers   5 мес. назад
21,904 views

425 Like   17 Dislike

Android Jetpack: ViewModel

ViewModel is part of the Lifecycle library which was designed to help you solve common Android Lifecycle challenges and to make your apps more maintainable and testable. A ViewModel holds your app's UI data in a lifecycle conscious way that survives configuration changes. Separating your app's UI data from your Activity and Fragment classes lets you better follow the single responsibility principle: Your Activities and Fragments are responsible for drawing data to the screen, while your ViewModel can take care of holding and processing all the data needed for the UI. Making a ViewModel is simple: * Adding the Lifecycle library to your build.gradle file * Extending the ViewModel class * Use ViewModelProviders to associate your ViewModel with your UI controller Then you can move all of your UI related data into your new ViewModel. If you need to customize ViewModel construction, you can create a ViewModelProvider.NewInstanceFactory. ViewModels also work great with the LiveData class to create reactive UIs! A few words of warning: don't store Contexts in ViewModels and don't confuse ViewModels with the onSaveInstanceState method. For more information, check out the video and links below! Gradle dependencies → https://goo.gl/nnrvKT ViewModels - A Simple Example (Good place to start for very basic usage) → https://goo.gl/pa2F1C ViewModel Documentation → https://goo.gl/T3Jrzt ViewModels - Persistence, onSaveInstanceState(), Restoring UI State and Loaders → https://goo.gl/LC1hXV Architecture Blueprint sample with Lifecycle library * Java → https://goo.gl/tPsEdh * Kotlin → https://goo.gl/L3NWQH Architecture Components samples → https://goo.gl/KCztpb ViewModels and LiveData Patterns and Antipatterns → https://goo.gl/1t3tmL Example of ViewModel factory in sample app → https://goo.gl/s7R86g Architecture Components landing page → https://d.android.com/arch Guide to app architecture → https://goo.gl/Vqtt34 Watch more Android Jetpack videos here → https://goo.gl/kw8LPv Subscribe to the Android Developers channel here → https://goo.gl/vLYDU #jetpack #featured

The farming robots of tomorrow are here today | The Future IRL

Robot farming machines are already doing the dirty work in more fields than people may realize. Subscribe to Engadget on YouTube: http://engt.co/subscribe Get More Engadget: • Like us on Facebook: http://www.facebook.com/engadget • Follow us on Twitter: http://www.twitter.com/engadget • Follow us on Instagram: http://www.instagram.com/engadget • Add us on Snapchat: https://www.snapchat.com/add/engadgetHQ • Read more: http://www.engadget.com Engadget is the definitive guide to this connected life.

Don't Waste $1000 on Data Recovery

Thanks to DeepSpar for sponsoring this video! Check out their RapidSpar Data Recovery Tool at http://geni.us/rapidspar RapidSpar is the first cloud-driven device built to help IT generalists and other non-specialized users recover client data from damaged or failing HDDs/SSDs Buy HDDs on Amazon: http://geni.us/sLlhDf Buy HDDs on Newegg: http://geni.us/a196 Linus Tech Tips merchandise at http://www.designbyhumans.com/shop/Linustechtips Linus Tech Tips posters at http://crowdmade.com/linustechtips Our Test Benches on Amazon: https://www.amazon.com/shop/linustechtips Our production gear: http://geni.us/cvOS Twitter - https://twitter.com/linustech Facebook - http://www.facebook.com/LinusTech Instagram - https://www.instagram.com/linustech Twitch - https://www.twitch.tv/linustech Intro Screen Music Credit: Title: Laszlo - Supernova Video Link: https://www.youtube.com/watch?v=PKfxm... iTunes Download Link: https://itunes.apple.com/us/album/sup... Artist Link: https://soundcloud.com/laszlomusic Outro Screen Music Credit: Approaching Nirvana - Sugar High http://www.youtube.com/approachingnir... Sound effects provided by http://www.freesfx.co.uk/sfx/

How 5G Works with Your Next Phone

Subscribe to Engadget on YouTube: http://engt.co/subscribe Get More Engadget: • Like us on Facebook: http://www.facebook.com/engadget • Follow us on Twitter: http://www.twitter.com/engadget • Follow us on Instagram: http://www.instagram.com/engadget • Read more: http://www.engadget.com Engadget is the original home for technology news and reviews.

LiveData is part of the Lifecycle library which was designed to help you solve common Android Lifecycle challenges and to make your apps more maintainable and testable.

LiveData is a lifecycle-aware observable. LiveData makes it easy to keep what's showing on screen in sync with the data. Benefits include:

* Lifecycle awareness: LiveData works well with the android lifecycle by only sending updates to UI components that are on screen and automatically removing listeners when a UI component is destroyed.
* Can be returned by Room, to learn more about Room → https://goo.gl/hWAq6R
* Reactive UIs with ViewModel and Data Binding
* Includes basic transformations map and switchMap and MediatorLiveData

LiveData is usually created in a ViewModel class → https://goo.gl/f3gTQx]

The Lifecycle library includes other classes that LiveData works with, including Lifecycle, LifecycleOwner and LifecycleObservable. To learn more about the Lifecycle library, check out → https://goo.gl/pouGCk

Gradle dependencies → https://goo.gl/xD4evT

Also take a look:

Room with a View Codelab [LiveData, ViewModel, Room and the architectural guidance] → http://bit.ly/2FS6YQD
Exposing error and loading state via LiveData → https://goo.gl/fjwccG
ViewModels and LiveData - Patterns and Antipatterns → https://goo.gl/1t3tmL
LiveData with SnackBar, Navigation and other events (the SingleLiveEvent case) → http://bit.ly/2rsmwGl
Subclassing LiveData → https://goo.gl/53Qq52
Using LifecycleObserver → https://goo.gl/e73zTc
Lifecycle codelab → https://goo.gl/OBkIfC
Guide to app architecture → https://goo.gl/tfae2D
Data Binding docs → http://bit.ly/2IjFicG

Watch more Android Jetpack videos here → https://goo.gl/kw8LPv

Subscribe to the Android Developers channel here → https://goo.gl/vLYDU

#AndroidJetpack #jetpack #featured

Comments for video: