Skip to content

2. Basic Usage

Gabor Varadi edited this page Mar 4, 2018 · 6 revisions

How to manipulate the backstack?

The Backstack provides 3 primary operators for manipulating state.

  • goTo(): if state does not previously exist in the backstack, then adds it to the stack. Otherwise navigate back to given state.
  • goBack(): returns boolean if StateChange is in progress, or if there are more than 1 entries in history (and handled the back press). Otherwise, return false.
  • setHistory(): sets the state to the provided elements, with the direction that is specified.

Typically, setHistory() is used with History . (or HistoryBuilder) class, which allows you to construct the List<T> with a builder pattern.

There are also 3 secondary operators, namely:

  • goUp()
  • goUpChain()
  • replaceTop()

You can obtain the Backstack from Navigator.getBackstack(context), or backstackDelegate.getBackstack(), depending on which class you use to integrate the BackstackManager.

Handling state changes

When the state stored by the backstack changes (meaning when you navigated from some view to another), the StateChanger is called to let you handle this state change.

When the state change is completed, the completion callback must be called.

Clone this wiki locally