public class

SliceLiveData.CachedSliceLiveData

extends LiveData<Slice>

 java.lang.Object

androidx.lifecycle.LiveData<Slice>

↳androidx.slice.widget.SliceLiveData.CachedSliceLiveData

Overview

Implementation of LiveData that provides controls over how cached vs live slices work.

Summary

Methods
public voidgoLive()

Moves this CachedSliceLiveData into a "live" state, causing the providing app to start up and provide an up to date version of the slice.

protected synchronized voidloadInitialSlice()

protected voidonActive()

Called when the number of active observers change from 0 to 1.

protected voidonInactive()

Called when the number of active observers change from 1 to 0.

public voidparseStream()

Generally the InputStream are parsed asynchronously once the LiveData goes into the active state.

protected voidupdateSlice()

from LiveData<T>getValue, hasActiveObservers, hasObservers, isInitialized, observe, observeForever, postValue, removeObserver, removeObservers, setValue
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public void parseStream()

Generally the InputStream are parsed asynchronously once the LiveData goes into the active state. When this is called, regardless of state, the slice will be read from the input stream and then the input stream's reference will be released when finished.

Calling parseStream() multiple times or after the stream has already been parsed asynchronously will have no effect.

public void goLive()

Moves this CachedSliceLiveData into a "live" state, causing the providing app to start up and provide an up to date version of the slice. After calling this method the slice will always be pinned as long as this LiveData is in the active state.

If the slice has already received a click or goLive() has already been called, then this method will have no effect.

Once goLive() has been called, there is no way to reverse it, this LiveData will then behave the same way as one created using SliceLiveData.fromUri(Context, Uri).

protected synchronized void loadInitialSlice()

protected void onActive()

Called when the number of active observers change from 0 to 1.

This callback can be used to know that this LiveData is being used thus should be kept up to date.

protected void onInactive()

Called when the number of active observers change from 1 to 0.

This does not mean that there are no observers left, there may still be observers but their lifecycle states aren't Lifecycle.State.STARTED or Lifecycle.State.RESUMED (like an Activity in the back stack).

You can check if there are observers via LiveData.hasObservers().

protected void updateSlice()