ContextAware
interface ContextAware
androidx.activity.contextaware.ContextAware |
A ContextAware
class is associated with a Context
sometime after the class is instantiated. By adding a OnContextAvailableListener
, you can receive a callback for that event.
Classes implementing ContextAware
are strongly recommended to also implement androidx.lifecycle.LifecycleOwner
for providing a more general purpose API for listening for creation and destruction events.
Summary
Public methods | |
---|---|
abstract Unit |
addOnContextAvailableListener(@NonNull listener: OnContextAvailableListener) Add a new |
abstract Context? |
Get the |
abstract Unit |
removeOnContextAvailableListener(@NonNull listener: OnContextAvailableListener) Remove a |
Extension functions | ||
---|---|---|
From androidx.activity.contextaware
|
Public methods
addOnContextAvailableListener
abstract fun addOnContextAvailableListener(@NonNull listener: OnContextAvailableListener): Unit
Add a new OnContextAvailableListener
for receiving a callback for when this class is associated with a android.content.Context
.
Listeners are triggered in the order they are added when added before the Context is available. Listeners added after the context has been made available will have the Context synchronously delivered to them as part of this call.
Parameters | |
---|---|
listener |
OnContextAvailableListener: The listener that should be added. |
peekAvailableContext
@Nullable abstract fun peekAvailableContext(): Context?
Get the Context
if it is currently available. If this returns null
, you can use addOnContextAvailableListener(OnContextAvailableListener)
to receive a callback for when it available.
Return | |
---|---|
Context? |
the Context if it is currently available. |
removeOnContextAvailableListener
abstract fun removeOnContextAvailableListener(@NonNull listener: OnContextAvailableListener): Unit
Remove a OnContextAvailableListener
previously added via addOnContextAvailableListener(OnContextAvailableListener)
.
Parameters | |
---|---|
listener |
OnContextAvailableListener: The listener that should be removed. |