Package icyllis.modernui.fragment

# Class OnBackPressedCallback

java.lang.Object
icyllis.modernui.fragment.OnBackPressedCallback

public abstract class OnBackPressedCallback extends Object
Class for handling `OnBackPressedDispatcher.onBackPressed()` callbacks.

This class maintains its own `enabled state`. Only when this callback is enabled will it receive callbacks to `handleOnBackPressed()`.

Note that the enabled state is an additional layer on top of the `LifecycleOwner` passed to `OnBackPressedDispatcher.addCallback(LifecycleOwner, OnBackPressedCallback)` which controls when the callback is added and removed to the dispatcher.

By calling `remove()`, this callback will be removed from any `OnBackPressedDispatcher` it has been added to. It is strongly recommended to instead disable this callback to handle temporary changes in state.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OnBackPressedCallback(boolean enabled)`
  Create a `OnBackPressedCallback`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract void`
  `handleOnBackPressed()`
  Callback for handling the `OnBackPressedDispatcher.onBackPressed()` event.
  `final boolean`
  `isEnabled()`
  Checks whether this callback should be considered enabled.
  `final void`
  `remove()`
  Removes this callback from any `OnBackPressedDispatcher` it is currently added to.
  `final void`
  `setEnabled(boolean enabled)`
  Set the enabled state of the callback.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### OnBackPressedCallback

    public OnBackPressedCallback(boolean enabled)
    Create a `OnBackPressedCallback`.
    Parameters:
      `enabled` - The default enabled state for this callback.
    See Also:
      - `setEnabled(boolean)`

- ## Method Details

  - ### setEnabled

    @UiThread public final void setEnabled(boolean enabled)
    Set the enabled state of the callback. Only when this callback is enabled will it receive callbacks to `handleOnBackPressed()`.

    Note that the enabled state is an additional layer on top of the `LifecycleOwner` passed to `OnBackPressedDispatcher.addCallback(LifecycleOwner, OnBackPressedCallback)` which controls when the callback is added and removed to the dispatcher.

    Parameters:
      `enabled` - whether the callback should be considered enabled

  - ### isEnabled

    @UiThread public final boolean isEnabled()
    Checks whether this callback should be considered enabled. Only when this callback is enabled will it receive callbacks to `handleOnBackPressed()`.
    Returns:
      Whether this callback should be considered enabled.

  - ### remove

    @UiThread public final void remove()
    Removes this callback from any `OnBackPressedDispatcher` it is currently added to.

  - ### handleOnBackPressed

    @UiThread public abstract void handleOnBackPressed()
    Callback for handling the `OnBackPressedDispatcher.onBackPressed()` event.