SliceLiveData.CachedSliceLiveData


public class SliceLiveData.CachedSliceLiveData extends LiveData


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

Summary

Public methods

void

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

void

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

Protected methods

void

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

void

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

Inherited methods

From androidx.lifecycle.LiveData
@Nullable T

Returns the current value.

boolean

Returns true if this LiveData has active observers.

boolean

Returns true if this LiveData has observers.

boolean

Returns whether an explicit value has been set on this LiveData.

void

Adds the given observer to the observers list within the lifespan of the given owner.

void

Adds the given observer to the observers list.

void
postValue(T value)

Posts a task to a main thread to set the given value.

void

Removes the given observer from the observers list.

void

Removes all observers that are tied to the given LifecycleOwner.

void

Sets the value.

Public methods

goLive

Added in 1.1.0-alpha02
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 fromUri.

parseStream

Added in 1.1.0-alpha02
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.

Protected methods

onActive

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.

onInactive

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 STARTED or RESUMED (like an Activity in the back stack).

You can check if there are observers via hasObservers.