Skip to content

Instantly share code, notes, and snippets.

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 joseprl89/76109c3a4ebff468c5cb7943fabab83d to your computer and use it in GitHub Desktop.
Save joseprl89/76109c3a4ebff468c5cb7943fabab83d to your computer and use it in GitHub Desktop.
How activeStateChanged delays the delivery of events until the lifecycle is active for Internals of Android Architecture Components Part II- LiveData
void activeStateChanged(boolean newActive) {
if (newActive == mActive) {
return;
}
// immediately set active state, so we'd never dispatch anything to inactive
// owner
mActive = newActive;
boolean wasInactive = LiveData.this.mActiveCount == 0;
LiveData.this.mActiveCount += mActive ? 1 : -1;
if (wasInactive && mActive) {
onActive();
}
if (LiveData.this.mActiveCount == 0 && !mActive) {
onInactive();
}
if (mActive) {
dispatchingValue(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment