SliceLiveData.CachedSliceLiveData


class SliceLiveData.CachedSliceLiveData : LiveData


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

Summary

Public functions

Unit

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

Unit

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

Protected functions

Unit

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

Unit

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

Inherited functions

From androidx.lifecycle.LiveData
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.

Unit
@MainThread
observe(owner: LifecycleOwner, observer: Observer<T!>)

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

Unit

Adds the given observer to the observers list.

Unit
postValue(value: T!)

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

Unit

Removes the given observer from the observers list.

Unit

Removes all observers that are tied to the given LifecycleOwner.

Unit
@MainThread
setValue(value: T!)

Sets the value.

Public functions

goLive

Added in 1.1.0-alpha02
fun goLive(): Unit

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
fun parseStream(): Unit

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 functions

onActive

protected fun onActive(): Unit

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 fun onInactive(): Unit

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.