接受生命周期事件并且做出相应处理
Posted liyanyan665
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接受生命周期事件并且做出相应处理相关的知识,希望对你有一定的参考价值。
LifecycleBoundObserver.java
------------------------------
class LifecycleBoundObserver extends ObserverWrapper implements GenericLifecycleObserver
@Override
public void onStateChanged(LifecycleOwner source, Lifecycle.Event event)
if (mOwner.getLifecycle().getCurrentState() == DESTROYED)
removeObserver(mObserver);
return;
activeStateChanged(shouldBeActive());
@Override
boolean shouldBeActive()
return mOwner.getLifecycle().getCurrentState().isAtLeast(STARTED);
ObserverWrapper.java
------------------------------
private abstract class ObserverWrapper
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(http://www.my516.com);
if (mActive)
dispatchingValue(this);
————————————————
以上是关于接受生命周期事件并且做出相应处理的主要内容,如果未能解决你的问题,请参考以下文章