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. Appreciating the persistence you put into your blog and detailed
    information you provide.


    Android Training in Chennai


    Android Training in Bangalore

    ReplyDelete
    Replies

    1. Great Article
      Cloud Computing Projects


      Networking Projects

      Final Year Projects for CSE


      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

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

    Best Android Training institute in Chennai
    Android Classes in Chennai

    ReplyDelete
  3. 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
  4. 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
  5. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Best Devops Training in pune
    excel advanced excel training in bangalore
    Devops Training in Chennai

    ReplyDelete
  6. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
    Best AWS Training in Chennai | Amazon Web Services Training in Chennai
    AWS Training in Bangalore | Amazon Web Services Training in Bangalore
    Amazon Web Services Training in Pune | Best AWS Training in Pune

    ReplyDelete
  7. There is a desire to earn a lot? Then come to us and win. top slot machine games online .Fate favors you, come in and win.

    ReplyDelete
  8. Качественный декоративный алюминиевый led профиль я обычно беру в компании Ekodio, советую.

    ReplyDelete
  9. 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
  10. 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
  11. 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
  12. Good post!Thank you so much for sharing this lovely article.It was so good to read and useful to upgrade my understanding...
    salesforce Training in Bangalore
    uipath Training in Bangalore
    blueprism Training in Bangalore

    ReplyDelete
  13. 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
  14. Accomplishing the ideal search for your kitchen is troublesome if the kitchen fixture isn't acceptable with the encompassing materials. A fair kitchen spigot can represent the deciding moment your idea, so it is indispensable to buy the best kitchen fixture for the activity as opposed to agreeing to something mediocre..
    visit kitchenfaucetinfo

    ReplyDelete
  15. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    ReplyDelete
  16. 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
  17. 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
  18. 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
  19. thanks for posting useful information.You have provided an nice article, Thank you very much for this one.Promobuddy is one of the best Digital Marketing Company in Ghaziabad experts in India.
    If you want to grow your Business Online, For more information, please visit our website:Digital Marketing Company in Ghaziabad
    SMM Services,
    PPC Services,
    SEM Services,
    Best Web Designing Company in India

    ReplyDelete
  20. 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
  21. 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
  22. 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
  23. Great Article
    Cloud Computing Projects


    Networking Projects

    Final Year Projects for CSE


    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete

Post a comment

Popular posts from this blog

Android Data Binding : Dynamic RecyclerView Adapter

Building a Cryptocurrency with Kotlin : Part 1