Class NavigationBackStack
-
- All Implemented Interfaces:
-
android.os.Parcelable
public class NavigationBackStack<T> implements Parcelable
Manages a browser like backstack of items.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
NavigationBackStack.NavigationItem
A single item on the navigation backstack.
public interface
NavigationBackStack.BackStackListener
Listener for changes to the navigation back stack.
-
Field Summary
Fields Modifier and Type Field Description public final static Parcelable.Creator<NavigationBackStack>
CREATOR
-
Constructor Summary
Constructors Constructor Description NavigationBackStack()
-
Method Summary
Modifier and Type Method Description void
addBackStackListener(@NonNull() NavigationBackStack.BackStackListener<T> backStackListener)
Adds a back stack listener to be notified of changes. void
removeBackStackListener(@NonNull() NavigationBackStack.BackStackListener<T> backStackListener)
Removes the back stack listener. void
clearBackStackListeners()
Removes all previously added back stack listeners. void
addItem(@NonNull() T item)
Adds a new item depending on if we are currently going back or forward. void
replaceWith(@NonNull() NavigationBackStack<T> navigationHistory)
Replaces navigation back stack with another instance. void
goBack()
Goes back one step, or does nothing if the stack is already empty. void
goForward()
Goes forward one step, or does nothing if the stack is already empty. T
getBackItem()
Returns the current top back item, or null. T
getForwardItem()
Returns the current top forward item, or null. void
resetForwardList()
Removes all forward navigation items. void
writeToParcel(Parcel dest, int flags)
int
describeContents()
-
-
Method Detail
-
addBackStackListener
void addBackStackListener(@NonNull() NavigationBackStack.BackStackListener<T> backStackListener)
Adds a back stack listener to be notified of changes. If the listener has already been added previously, this method will be a no-op. Adding
null
is not allowed, and will result in an exception.- Parameters:
backStackListener
- BackStackListener that should be notified.
-
removeBackStackListener
void removeBackStackListener(@NonNull() NavigationBackStack.BackStackListener<T> backStackListener)
Removes the back stack listener. Upon calling this method the
listener
will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Addingnull
is not allowed,and will result in an exception.- Parameters:
backStackListener
- BackStackListener that should be removed.
-
clearBackStackListeners
void clearBackStackListeners()
Removes all previously added back stack listeners. To remove just one listener use removeBackStackListener. Upon calling this method no listeners will be notified of any changes.
-
addItem
void addItem(@NonNull() T item)
Adds a new item depending on if we are currently going back or forward.
- Parameters:
item
- The item to add.
-
replaceWith
void replaceWith(@NonNull() NavigationBackStack<T> navigationHistory)
Replaces navigation back stack with another instance. Keeps all back stack listeners.
- Parameters:
navigationHistory
- New navigation back stack.
-
goBack
void goBack()
Goes back one step, or does nothing if the stack is already empty.
-
goForward
void goForward()
Goes forward one step, or does nothing if the stack is already empty.
-
getBackItem
@Nullable() T getBackItem()
Returns the current top back item, or null.
-
getForwardItem
@Nullable() T getForwardItem()
Returns the current top forward item, or null.
-
resetForwardList
void resetForwardList()
Removes all forward navigation items.
-
writeToParcel
void writeToParcel(Parcel dest, int flags)
-
describeContents
int describeContents()
-
-
-
-