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.
Example
class MySession : Session() {
private val mapboxCarContext = MapboxCarContext(lifecycle, MapboxCarMap())
.prepareScreens()
--snip--
}
Customization
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.
MapboxScreenManager.replaceTop("MY_SCREEN")
Functions
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.
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.
Allows you to put all defined screen factories into the manager in one operation.
Returns the previously set screen factory.