ContextAwareHelper


class ContextAwareHelper


Helper class for implementing ContextAware. Classes using this helper should call addOnContextAvailableListener and removeOnContextAvailableListener as the respective methods of ContextAware are called.

You must call dispatchOnContextAvailable once the Context is available to dispatch the callbacks to all registered listeners.

Listeners added after the context has been made available via dispatchOnContextAvailable will have the Context synchronously delivered to them up until clearAvailableContext is called.

Summary

Public constructors

Public functions

Unit

Add a new OnContextAvailableListener for receiving a callback for when this class is associated with a android.content.Context.

Unit

Clear any Context previously made available via dispatchOnContextAvailable.

Unit

Dispatch the callback of OnContextAvailableListener.onContextAvailable to all currently added listeners in the order they were added.

Context?

Get the Context if it is currently available.

Unit

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

Public constructors

ContextAwareHelper

Added in 1.2.0
ContextAwareHelper()

Public functions

addOnContextAvailableListener

Added in 1.2.0
fun addOnContextAvailableListener(listener: OnContextAvailableListener): Unit

Add a new OnContextAvailableListener for receiving a callback for when this class is associated with a android.content.Context.

Parameters
listener: OnContextAvailableListener

The listener that should be added.

clearAvailableContext

Added in 1.2.0
fun clearAvailableContext(): Unit

Clear any Context previously made available via dispatchOnContextAvailable.

dispatchOnContextAvailable

Added in 1.2.0
fun dispatchOnContextAvailable(context: Context): Unit

Dispatch the callback of OnContextAvailableListener.onContextAvailable to all currently added listeners in the order they were added.

Parameters
context: Context

The Context the ContextAware object is now associated with.

peekAvailableContext

Added in 1.2.0
fun peekAvailableContext(): Context?

Get the Context if it is currently available. If this returns null, you can use addOnContextAvailableListener to receive a callback for when it available.

Returns
Context?

the Context if it is currently available.

removeOnContextAvailableListener

Added in 1.2.0
fun removeOnContextAvailableListener(listener: OnContextAvailableListener): Unit

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

Parameters
listener: OnContextAvailableListener

The listener that should be removed.