Created
May 27, 2018 20:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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