NavManagerService

Represent a remote Navigation Service, serving different requests like search and navigation.

NOTE:

  • Any method can return Result.failure(NavManagerServiceException()).

  • Every method will return ConnectionDeadException when the connection is dead or disposed, which means a new connection is required.

  • All Flow will avoid throwing any exceptions, but you still must still call Flow.catch to avoid unexpected crashes.

  • Because none the Flow will throw ConnectionDeadException, you should call observeIsConnectionAlive to receive the event of connection death.

Example usage:

val serviceResult = NavManagerService.connect(
this@Activity.applicationContext as Application,
"com.mapbox.dash.app",
)

var service = serviceResult.fold(
{ it },
{ return@launch }
)

val res = service.search("mcdonalds", SearchOptions())
if (res.isFailure) {
if (res.exceptionOrNull() is ConnectionDeadException) {
service = // maybe reconnect
}
}

val searchResults = res.getOrNull()!!
if (searchResults.isNotEmpty()) {
val navigationRes = service.navigateTo(searchResults.first(), emptyList())
// Check navigationRes
}

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun NavManagerService.back(letAppMoveToBackground: Boolean = false): Result<Unit>

Sends a back request to the navigation app, which is an equivalent to the back click.

Link copied to clipboard
abstract fun dispose()

Must be called to free resources when the service is no longer needed. Must be called even if methods start returning ConnectionDeadException.

Link copied to clipboard

Lets the caller know if the nav app is in the foreground (i.e. is STARTED/RESUMED).

Link copied to clipboard

Sends a request to the navigation app to call Activity.moveTaskToBack, which should move the app to the background if it is in the foreground.

Link copied to clipboard

Lets the caller observe the foreground state of the nav app.

Link copied to clipboard
abstract fun observeIsConnectionAlive(): Flow<Boolean>

Observes the death of connection.