class MapboxScreenManager

MapboxScreenManager allows you to prepare an experience that includes many screens with a single function. Use the MapboxCarContext.prepareScreens to get started.

How it works

Using String to MapboxScreenFactory pairing, the MapboxScreenManager will create a screen based on a string provided. You can customize screens by setting the key value pair.

MapboxScreenManager can be observed and controlled by the car or app. Observe the screen changes with MapboxScreenManager.screenEvent, change the screen with operations like MapboxScreenManager.replaceTop. See the MapboxScreenOperation for all of the available operations, each operation is applied through MapboxScreenManager functions.

Set up

The MapboxScreenManager is provided to you through the MapboxCarContext. It is important to keep the screen manager lifecycle close to CarContext to avoid memory leaks. MapboxScreenManager does not work without the ScreenManager which is also bound to the CarContext.


class MySession : Session() {
private val mapboxCarContext = MapboxCarContext(lifecycle, MapboxCarMap())


At any point, you can change the mapping of the MapboxScreenManager with setters. The MapboxScreenFactory instances are expected to have a lifecycle as long as the Session, so an instance of MapboxScreenManager is required. You can access this class through the

MapboxScreenFactory.create Example

mapboxCarContext.screenManager["MY_SCREEN"] = MyScreenFactory()

// When your app is showing on the Android Auto head unit, the MyScreenFactory will be shown
// on the top of the back stack.


Link copied to clipboard
object Companion


Link copied to clipboard
operator fun contains(key: String): Boolean

Check if there is a factory assigned to the key. This can be used to assign a factory when there is not one set. This can also be used to verify the type of the factory.

Link copied to clipboard
fun createScreen(screenKey: String): Screen

This should be used to create a screen from Session.onCreateScreen. If the screen changes the screenEvent observers will be notified with an MapboxScreenOperation.CREATED event.

Link copied to clipboard
fun goBack(): Boolean

Calling this function will pop the back stack of the ScreenManager. If there are no screens on the backstack, it will safely return false. If you are using the ScreenManager and the goBack operation results in an unknown backstack, this will throw an IllegalStateException.

Link copied to clipboard
fun putAll(vararg pairs: Pair<String, MapboxScreenFactory>): MapboxScreenManager

Allows you to put all defined screen factories into the manager in one operation.

Link copied to clipboard
operator fun <T : MapboxScreenFactory> set(key: String, factory: T): MapboxScreenFactory?

Returns the previously set screen factory.