mapbox / mapbox/mapbox-navigation-android
Black screen on resume
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
**Android API:**
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
**Mapbox Navigation SDK version:**
com.mapbox.navigation:ui:1.6.1
### Steps to trigger behavior
#### Steps ####
1. Initialize MapboxMap
2. Put the application into the background
3. Draw route on map using `mapboxMap.getStyle`
4. Re open the application and experience a black screen
5. If you leave the app and open again the map shows with route, any interaction done to the black screen is visible which seems to indicate the map is interact-able during the black screen stage
Black screen does not appear if we stay on app at all time. Black screen does not appear when using Android 11, only when using Android 10 in both emulator and actual device.
#### Screen Capture ####
https://user-images.githubusercontent.com/31061195/124678466-68767400-de77-11eb-93b0-e94def827862.mp4
#### Code Snippet ####
```
class MBNavigationView(reactContext: ThemedReactContext) : NavigationView(reactContext), OnNavigationReadyCallback, LifecycleEventListener {
// Where we initialize the mapboxMap variable
override fun onMapReady(mapboxMap: MapboxMap) {
this.mapboxMap = mapboxMap
if (this.theme == "dark") {
this.mapboxMap.setStyle(Style.TRAFFIC_NIGHT)
} else {
this.mapboxMap.setStyle(Style.TRAFFIC_DAY)
}
super.onMapReady(mapboxMap)
}
```
This gets called when we need to display map and a route
```
fun showOffer(location: ReadableMap?) {
// remove previous offer
mapboxMap.getStyle {
it.removeLayer("ROUTE_LAYER_ID")
it.removeLayer("MARKER_LAYER_ID")
it.removeSource("ROUTE_LINE_SOURCE_ID")
it.removeSource("MARKER_SOURCE_ID")
it.removeImage("ICON_ID")
}
val locationLongitude = location?.getDouble("longitude")
val locationLatitude = location?.getDouble("latitude")
if (locationLongitude !== null && locationLatitude !== null) {
val locationPoint = Point.fromLngLat(locationLongitude, locationLatitude)
calculateDirections(locationPoint, offerRoutesCallback)
}
}
private fun drawOfferRoute(route: DirectionsRoute) {
// Show the map
mapboxMap.getStyle {
mapboxMap.locationComponent?.apply {
activateLocationComponent(
LocationComponentActivationOptions.builder(
reactContext,
it
)
.build()
)
isLocationComponentEnabled = true
cameraMode = CameraMode.TRACKING
renderMode = RenderMode.COMPASS
}
val routeLineString = LineString.fromPolyline(route.geometry()!!,6)
it.addSource( GeoJsonSource("ROUTE_LINE_SOURCE_ID",
FeatureCollection.fromFeature(Feature.fromGeometry(routeLineString))
))
val coordinates = route.routeOptions()?.coordinates()
if(coordinates !== null) {
it.addSource( GeoJsonSource("MARKER_SOURCE_ID",
FeatureCollection.fromFeature(Feature.fromGeometry(coordinates[coordinates.size - 1]))
))
}
it.addImage(
"ICON_ID",
BitmapUtils.getBitmapFromDrawable(
ContextCompat.getDrawable(
reactContext,
R.drawable.mapbox_marker_icon_default
)
)!!
)
// Find the bounds for the routeLineString
val latLngBounds: LatLngBounds = LatLngBounds.Builder().includes(routeLineString.coordinates().map { point -> LatLng(point.latitude(), point.longitude()) }).build()
val padding = 150
val offerCardHeight = 250
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, padding, padding * 2, padding, padding + offerCardHeight))
it.addLayer( LineLayer("ROUTE_LAYER_ID", "ROUTE_LINE_SOURCE_ID").withProperties(
PropertyFactory.lineWidth(10f),
PropertyFactory.lineCap(LINE_CAP_ROUND),
PropertyFactory.lineColor(Color.parseColor("#4794f9"))
))
it.addLayerAbove( SymbolLayer("MARKER_LAYER_ID", "MARKER_SOURCE_ID").withProperties(
iconImage("ICON_ID"), iconIgnorePlacement(true)
), "ROUTE_LAYER_ID")
}
}
private val offerRoutesCallback = object: RoutesRequestCallback {
override fun onRoutesReady(routes: List) {
drawOfferRoute(routes[0])
hideLoading()
}
}
}
```
### Expected behavior
Does not experience black screen when re opening the application
### Actual behavior
There is a black screen while re opening the application which only seems to go away if I close/open the application again
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MBNavigationView lifecycle and map rendering flow shown in the issue, especially onMapReady, showOffer, and drawOfferRoute. Reproduce the resume sequence on Android 10 with Mapbox Navigation SDK 1.6.1, then investigate why the map is interactive while black; done means reopening after backgrounding displays the map and route without requiring a second restart.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100