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.
Call MapboxNavigationApp.setup to specify your NavigationOptions.
Register and unregister your MapboxNavigationObserver instances with MapboxNavigationApp.registerObserver and MapboxNavigationApp.unregisterObserver.
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
Functions
Individually attach a lifecycle onto the MapboxNavigationApp. If the app has been setup, then this lifecycle will cause MapboxNavigation to be created.
Detect when any Activity is in the foreground. Use attach and detach for granular control of which lifecycle is used for creating MapboxNavigation.
MapboxNavigation has functions that do not require observation streams. This function allows you to get the current instance to call those functions.
Individually detach lifecycles from MapboxNavigationApp. When all LifecycleOwners have been detached, this will cause all MapboxNavigationObserver.onDetached.
Optional function to detach all observers and disable MapboxNavigation from being created. You can re-enable MapboxNavigation by calling MapboxNavigationApp.setup.
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.
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.
Register an observer to receive the MapboxNavigation instance.
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.
Unregister the observer that was registered through registerObserver.