"Android" Architecture Components Best Practices--lifecycles

Source: Internet
Author: User
  • The less code in UI controllers (activities and fragments), the better, you should not request data yourself, but instead use ViewModel to update the data, and listen to Livedata to update the UI
  • The UI in UI controllers is written as data-driven, which is what the UI controller needs to do to update the view when the data changes, or to give viewmodel feedback when the user has input behavior
  • Putting the data logic in ViewModel, ViewModel exists to separate the UI controller from everything else in the application. ViewModel's role is not to take data (such as from the network, from the database), but to tell the corresponding component what it should do, and then provide the UI controller with the returned data
  • You can use databinding to ensure code clarity between the UI controllers and the view. If we want to update the UI, then we can not avoid the UI controllers to write the updated code, Java, of course, butter knife and other things to play a similar purpose
  • If the UI is more complex, you can create presenter for UI updates, sometimes writing more code, but it's easy to test
  • ViewModel never hold a reference to a view or activity that could cause a memory leak

"Android" Architecture Components Best Practices--lifecycles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.