MapboxNavigationApp

object 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)
}
}

Functions

Link copied to clipboard
fun attach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp

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
fun attachAllActivities(application: Application): MapboxNavigationApp

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
fun current(): MapboxNavigation?

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
fun detach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp

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

Link copied to clipboard
fun disable(): MapboxNavigationApp

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
fun <T : MapboxNavigationObserver> getObserver(clazz: Class<T>): T

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.

fun <T : MapboxNavigationObserver> getObserver(kClass: KClass<T>): T

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
fun <T : MapboxNavigationObserver> getObservers(clazz: Class<T>): List<T>

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

fun <T : MapboxNavigationObserver> getObservers(kClass: KClass<T>): List<T>

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
fun isSetup(): Boolean

Indicates whether the MapboxNavigationApp has been setup.

Link copied to clipboard
fun registerObserver(mapboxNavigationObserver: MapboxNavigationObserver): MapboxNavigationApp

Register an observer to receive the MapboxNavigation instance.

Link copied to clipboard
fun setup(navigationOptions: NavigationOptions): MapboxNavigationApp

Call MapboxNavigationApp.setup to provide the application with NavigationOptions.

fun setup(navigationOptionsProvider: NavigationOptionsProvider): MapboxNavigationApp

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

Link copied to clipboard
fun unregisterObserver(mapboxNavigationObserver: MapboxNavigationObserver): MapboxNavigationApp

Unregister the observer that was registered through registerObserver.

Properties

Link copied to clipboard
val lifecycleOwner: LifecycleOwner

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.