Android Architecture Components : LiveData


Live Data : Life-cycle aware Observables


As an Android developer you often have to work with data that is dynamic and changing with user input, device configuration changes, or even time changes. On top of this as a developer you have to respect the life-cycle of an Activity of Fragment that contains this dynamically changing data: stop updates onStop() or onPause() and restart the updates onStart() and onResume(). Examples of this is location data, countdown timers, user's list selections and any other type of dynamically changing data. Lets see how we can make these tasks easier using LiveData. We will demonstrate LiveData by creating a self contained timer.

Subclass LiveData

LiveData object is set active when the observer's lifecycle is stated or resumed. And the LiveData object is set inactive when the observer's lifecycle is stopped or pause. In our TimerLiveData we start timer when onActive() is called and stop the timer when onInactive() is called. This way the observer only gets timer updates while it is active.

Observe with LifecycleOwner

Instantiate the TimerLiveData object and then observe() in order to get callbacks on timer's value changes but only while our Activity is active.

Benefits of using LiveData

  • Makes objects life-cycle aware
  • Keeps LiveData objects self contained
  • Keeps Activitys and Fragments clean
  • Eliminates memory leaks as LiveData objects clean up themselves.
  • Observers instantly notified of value changes in LiveData

Comments

  1. Very interesting and useful presentation to understand the architecture of Android. Thank you.

    Best Android Training institute in Chennai
    Android Classes in Chennai

    ReplyDelete
  2. You’ve written a really great article here. Your writing style makes this material easy to understand.. I agree with some of the many points you have made. Thank you for this is real thought-provoking content
    Python training in bangalore
    Python course in pune
    Python training in bangalore

    ReplyDelete
  3. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.

    rpa training in chennai
    rpa training in bangalore
    rpa course in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  4. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    If you are looking for any Big data Hadoop Related information please visit our website Big Data Hadoop Training In Bangalore page!

    ReplyDelete
  5. Excellent information with unique content and it is very useful to know about the information based on blogs...
    salesforce Training in Bangalore
    uipath Training in Bangalore
    blueprism Training in Bangalore

    ReplyDelete
  6. Informative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.
    click here to enable adobe flash player
    click here
    visit here
    check it out
    visit for more

    ReplyDelete
  7. Subscription boxes are a type of boxes which are delivered to the regular customers in order to build goodwill of the brand. They are also a part of the product distribution strategy. As a woman, you should subscribe to these boxes to bless yourself with a new and astonishing box of happiness each month. visit mysubscriptionsboxes

    ReplyDelete
  8. Thanks for sharing your innovative ideas to our vision. I have read your blog and I gathered some new information through your blog. Your blog is really very informative and unique. Keep posting like this. Awaiting for your further update.If you are looking for any Data science related information, please visit our website Data science training institute in btm layout

    ReplyDelete
  9. Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective...

    Start your journey with Best SAP Course and get hands-on Experience with 100% Placement assistance from experts Trainers @Softgen Infotech Located in BTM Layout Bangalore. Expert Trainers with 8+ Years of experience, Free Demo Classes Conducted.

    ReplyDelete
  10. It's such a superb and helpful post..
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    If you need any logo then,
    Please visit our site,
    buylogo

    ReplyDelete
  11. This is an excellent and helpful information...

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery

    ReplyDelete
  12. Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.share somemore coding related to this program...
    AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery

    ReplyDelete
  13. Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information speciall development I care for such info a lot.
    Java training in chennai | Java training in bangalore | Java training in hyderabad | Java training in coimbatore | Java training in online

    ReplyDelete
  14. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
    amazon web services aws training in chennai

    microsoft azure course in chennai

    workday course in chennai

    android course in chennai

    ios course in chennai

    ReplyDelete
  15. The Blog contains the effective and attractive information’s and thanks for the blog.
    JAVA Training in Chennai
    JAVA Training in Bangalore

    ReplyDelete
  16. Online casino in Kerala - KDAL - KDAL
    Online หาเงินออนไลน์ casino in Kerala is the new online casino that launched in 2018 by Kambal. 제왕 카지노 This new casino aims to ensure that the best 온카지노 entertainment for players is

    ReplyDelete
  17. This article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. bitmain antminer l7

    ReplyDelete
  18. DJay Pro AI Crack is a revolutionary technology to deconstruct and mix music in real-time. Instantly isolate beats, instruments.Djay Pro Mac Crack

    ReplyDelete
  19. Best Manifestation Books · Super Attractor · Manifest Your Destiny · Ask and It Is Given · The Power of Now · You Can Heal Your Life · The Magic of Manifesting.Best-Manifestation-Books

    ReplyDelete
  20. Tea TV is an entertainment application that allows users to stream movies and TV shows on their mobile devices. It offers premium features, such as ad-free streaming, access to exclusive content, and high-quality video playback, without requiring users to pay a subscription fee.

    ReplyDelete

Post a Comment

Popular posts from this blog

Building a Cryptocurrency with Kotlin : Part 1

Clean Code: Meaningful Names