Register now for Android Dev Summit 2019!

SliceLiveData.CachedSliceLiveData

public static class SliceLiveData.CachedSliceLiveData
extends LiveData<Slice>

java.lang.Object
   ↳ androidx.lifecycle.LiveData<androidx.slice.Slice>
     ↳ androidx.slice.widget.SliceLiveData.CachedSliceLiveData


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

Summary

Public methods

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.

void parseStream()

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

Protected methods

void onActive()

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

void onInactive()

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

Inherited methods

Public methods

goLive

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).

parseStream

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 to 1 from 0.

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

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