OnMapPanningListener

Hi,

When the app going into background onMapPanningListener is removed. How can i prevent that? At the moment i add and remove the listener at onStop and OnResume.

Hi,

I’m trying to reproduce the issue but however in my demo application everything works as intended.

Here is my code:

override fun onResume() {
    super.onResume()
    registerListener()
}

override fun onPause() {
    super.onPause()
    unregisterListener()
}

private fun registerListener() {
    tomtomMap.addOnMapPanningListener(panningListener)
}

private fun unregisterListener() {
    removeOnMapPanningListener(panningListener)
}

private val panningListener: TomtomMapCallback.OnMapPanningListener =
    object : TomtomMapCallback.OnMapPanningListener {
        override fun onMapPanningStarted() {
            displayMessage("Panning started")
        }

        override fun onMapPanningOngoing() {
            displayMessage("Panning ongoing")
        }

        override fun onMapPanningEnded() {
            displayMessage("Panning ended")
        }
    }

Can you provide more details and code to reproduce this issue?

Hi Damian,

What i meant is it that onStart() i add onMapPanningListener and if the app goes into background the listener is removed. Same happens when a route is added to the map. Your example works because you are doing the same as me, adding the listener onResume() and removing it onPause() or onStop(). If u add the listener once onStart(), then it should stay there until it is removed?

I see now, so In the SDK all callbacks are removed in onPause() method so your callback wont be preserved when app goes into background. You need to register the same callback each time your app goes back from background.

I thought so. Just wanted to make sure that is not an error on my part. Thank you.

1 Like