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
}
Functions
Must be called to free resources when the service is no longer needed. Must be called even if methods start returning ConnectionDeadException.
Lets the caller know if the nav app is in the foreground (i.e. is STARTED/RESUMED).
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.
Lets the caller observe the foreground state of the nav app.
Observes the death of connection.