Search code examples
javaandroidkotlinmapboxmapbox-android

Mapbox OfflineRegionObserver listener unregister


I am trying to implement offline region download. I am using the OfflineRegionObserver to listen to the changes in the offline region. The documentation says the observer gets notified when there is any change in the region status. My use case is I want to unregister form this listener when the user presses cancel. Bu I can't find any explicit way to unregister it. Which makes it a candidate for leaks.

    offlineRegion.setObserver(object : OfflineRegion.OfflineRegionObserver {
    override fun mapboxTileCountLimitExceeded(limit: Long) {
    }

    override fun onStatusChanged(status: OfflineRegionStatus?) {
    }

    override fun onError(error: OfflineRegionError?) {
    }

})

Now how can I unregister form this listener when I want it to happen. I want the unregister to be in my control.


Solution

  • You can call offlineRegion.setObserver(null) to unregister the listener.