MapboxNavigationApp

object MapboxNavigationApp

Manages a default lifecycle for MapboxNavigation.

  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

attach
Link copied to clipboard
fun attach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp
Individually attach a lifecycle onto the MapboxNavigationApp.
attachAllActivities
Link copied to clipboard
fun attachAllActivities(application: Application): MapboxNavigationApp
Detect when any Activity is in the foreground.
current
Link copied to clipboard
fun current(): MapboxNavigation?
MapboxNavigation has functions that do not require observation streams.
detach
Link copied to clipboard
fun detach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp
Individually detach lifecycles from MapboxNavigationApp.
disable
Link copied to clipboard
fun disable(): MapboxNavigationApp
Optional function to detach all observers and disable MapboxNavigation from being created.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
getObserver
Link copied to clipboard
fun <T : MapboxNavigationObserver> getObserver(kClass: KClass<T>): T
Provides access to any registered observer instance.
hashCode
Link copied to clipboard
open fun hashCode(): Int
isSetup
Link copied to clipboard
fun isSetup(): Boolean
Indicates whether the MapboxNavigationApp has been setup.
registerObserver
Link copied to clipboard
fun registerObserver(mapboxNavigationObserver: MapboxNavigationObserver): MapboxNavigationApp
Register an observer to receive the MapboxNavigation instance.
setup
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.
toString
Link copied to clipboard
open fun toString(): String
unregisterObserver
Link copied to clipboard
fun unregisterObserver(mapboxNavigationObserver: MapboxNavigationObserver): MapboxNavigationApp
Unregister the observer that was registered through registerObserver.

Properties

lifecycleOwner
Link copied to clipboard
val lifecycleOwner: LifecycleOwner
Get the lifecycle of the car and app.