ContextAware
public
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
LifecycleOwner
for providing a more general purpose API for
listening for creation and destruction events.
See also:
Summary
Public methods | |
---|---|
abstract
void
|
addOnContextAvailableListener(OnContextAvailableListener listener)
Add a new |
abstract
Context
|
peekAvailableContext()
Get the |
abstract
void
|
removeOnContextAvailableListener(OnContextAvailableListener listener)
Remove a |
Public methods
addOnContextAvailableListener
public abstract void addOnContextAvailableListener (OnContextAvailableListener listener)
Add a new OnContextAvailableListener
for receiving a callback for when
this class is associated with a 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
public abstract Context peekAvailableContext ()
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.
Returns | |
---|---|
Context |
the Context if it is currently available. |
removeOnContextAvailableListener
public abstract void removeOnContextAvailableListener (OnContextAvailableListener listener)
Remove a OnContextAvailableListener
previously added via
addOnContextAvailableListener(OnContextAvailableListener)
.
Parameters | |
---|---|
listener |
OnContextAvailableListener : The listener that should be removed. |