Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created December 28, 2020 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/6b94fca92d65c0c159923d25b65fc99c to your computer and use it in GitHub Desktop.
Save magdamiu/6b94fca92d65c0c159923d25b65fc99c to your computer and use it in GitHub Desktop.
Slow rendering best practices
// NOT OK
void onNewEmailsArrivedNotRecommended(List<Email> newEmails) {
emailAdapter.setEmails(newEmails);
emailAdapter.notifyDataSetChanged();
}
// OK
void onNewDataArrivedFastRendering(List<Email> newEmails) {
List<Email> oldEmails = emailAdapter.getEmails();
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new EmailDiffCallback(oldEmails, newEmails));
emailAdapter.setEmails(newEmails);
result.dispatchUpdatesTo(emailAdapter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment