ScreenManager


@MainThread
public class ScreenManager implements Manager

TestScreenManager

The ScreenManager that is used for testing.


Manages the stack of Screens and their respective Lifecycles.

Summary

Public methods

@NonNull Collection<Screen>

Returns the copy of the current screen stack as a type Collection

int

Returns the current stack size.

@NonNull Screen

Returns the Screen that is at the top of the stack.

void
pop()

Pops the top Screen from the stack.

void
popTo(@NonNull String marker)

Removes screens from the top of the stack until a Screen which has the given marker is found, or the root has been reached.

void

Removes all screens from the stack until the root has been reached.

void
push(@NonNull Screen screen)

Pushes the screen to the stack.

void
pushForResult(
    @NonNull Screen screen,
    @NonNull OnScreenResultListener onScreenResultListener
)

Pushes a Screen, for which you would like a result from, onto the stack.

void

Removes the screen from the stack.

Public methods

getScreenStack

Added in 1.4.0
public @NonNull Collection<ScreengetScreenStack()

Returns the copy of the current screen stack as a type Collection

getStackSize

Added in 1.1.0
public int getStackSize()

Returns the current stack size.

getTop

Added in 1.0.0
public @NonNull Screen getTop()

Returns the Screen that is at the top of the stack.

Throws
java.lang.NullPointerException

if the method is called before a Screen has been pushed to the stack via push, or pushForResult, or returning a Screen from onCreateScreen

java.lang.IllegalStateException

if the current thread is not the main thread

pop

Added in 1.0.0
public void pop()

Pops the top Screen from the stack.

If the top Screen is the only Screen in the stack, it will not be removed.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Throws
java.lang.IllegalStateException

if the current thread is not the main thread

popTo

Added in 1.0.0
public void popTo(@NonNull String marker)

Removes screens from the top of the stack until a Screen which has the given marker is found, or the root has been reached.

The root Screen will not be popped.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Throws
java.lang.NullPointerException

if marker is null

java.lang.IllegalStateException

if the current thread is not the main thread

See also
setMarker

popToRoot

Added in 1.0.0
public void popToRoot()

Removes all screens from the stack until the root has been reached.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Throws
java.lang.IllegalStateException

if the current thread is not the main thread

push

Added in 1.0.0
public void push(@NonNull Screen screen)

Pushes the screen to the stack.

If the screen pushed is already in the stack it will be moved to the top of the stack.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Throws
java.lang.NullPointerException

if screen is null

java.lang.IllegalStateException

if the current thread is not the main thread

pushForResult

Added in 1.0.0
public void pushForResult(
    @NonNull Screen screen,
    @NonNull OnScreenResultListener onScreenResultListener
)

Pushes a Screen, for which you would like a result from, onto the stack.

When the given screen finishes, the onScreenResultCallback will receive a callback to onScreenResult with the result that the pushed screen set via setResult.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Parameters
@NonNull Screen screen

the Screen to push on top of the stack

@NonNull OnScreenResultListener onScreenResultListener

the listener that will be executed with the result pushed by the screen through setResult. This callback will be executed on the main thread

Throws
java.lang.NullPointerException

if either the screen or the onScreenResultCallback are null

java.lang.IllegalStateException

if the current thread is not the main thread

remove

Added in 1.0.0
public void remove(@NonNull Screen screen)

Removes the screen from the stack.

If the screen is the only Screen in the stack, it will not be removed.

If the app's lifecycle is already in the DESTROYED state, this operation is a no-op.

Throws
java.lang.NullPointerException

if screen is null

java.lang.IllegalStateException

if the current thread is not the main thread