MapboxNavigationApp

Manages a default lifecycle for MapboxNavigation.

Alternative way of obtaining the instance of the MapboxNavigation is MapboxNavigationProvider.

Note that MapboxNavigationProvider and MapboxNavigationApp can't be used together at the same time.

  1. Call MapboxNavigationApp.setup to specify your NavigationOptions.

  2. Register and unregister your MapboxNavigationObserver instances with MapboxNavigationApp.registerObserver and MapboxNavigationApp.unregisterObserver.

  3. Attach and detach LifecycleOwners to create instances of MapboxNavigation.

Examples

Register and unregister individual LifecycleOwners. Below is an example of creating a single activity that uses MapboxNavigation.

class MyActivity : ComponentActivity() {
override fun onCreate() {
MapboxNavigationApp
.setup(navigationOptions)
.attach(this)
}
override fun onResume() {
MapboxNavigationApp
.registerObserver(locationObserver)
}
override fun onPause() {
MapboxNavigationApp
.unregisterObserver(locationObserver)
}
}

Alternatively, you can enable an entire application by attaching all activities. This will make a MapboxNavigation instance available to any activity or fragment.

class MyApplication : Application() {
override fun onCreate() {
MapboxNavigationApp.setup(this)
.attachAllActivities()
.registerObserver(locationObserver)
}
}

Properties

Link copied to clipboard

Get the lifecycle of the car and app. It is started when either the car or app is in foreground. When both the car and app have been closed, the lifecycle is stopped. The lifecycle is never destroyed.

Functions

Link copied to clipboard

Individually attach a lifecycle onto the MapboxNavigationApp. If the app has been setup, then this lifecycle will cause MapboxNavigation to be created.

Link copied to clipboard

Detect when any Activity is in the foreground. Use attach and detach for granular control of which lifecycle is used for creating MapboxNavigation.

Link copied to clipboard

MapboxNavigation has functions that do not require observation streams. This function allows you to get the current instance to call those functions.

Link copied to clipboard

Individually detach lifecycles from MapboxNavigationApp. When all LifecycleOwners have been detached, this will cause all MapboxNavigationObserver.onDetached.

Link copied to clipboard

Optional function to detach all observers and disable MapboxNavigation from being created. You can re-enable MapboxNavigation by calling MapboxNavigationApp.setup.

Link copied to clipboard

Java interoperability. Provides access to any registered observer instance. If multiple instances of the same class have been registered, the first observer will be returned.

Provides access to any registered observer instance. If multiple instances of the same class have been registered, the first observer will be returned.

Link copied to clipboard

Java interoperability. Provides access to any registered observer instance. If no observers have been registered with this class type, an empty list is returned.

Provides access to any registered observer instance. If no observers have been registered with this class type, an empty list is returned.

Link copied to clipboard

Indicates whether the MapboxNavigationApp has been setup.

Link copied to clipboard

Register an observer to receive the MapboxNavigation instance.

Link copied to clipboard

Call MapboxNavigationApp.setup to provide the application with NavigationOptions.

Call MapboxNavigationApp.setup to provide the application with NavigationOptionsProvider. New NavigationOptions will be created for every MapboxNavigation instance.

Link copied to clipboard

Unregister the observer that was registered through registerObserver.