Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps SDK for Android : map-display ANR #102

Open
zhangwenxiang26 opened this issue Jun 20, 2024 · 0 comments
Open

Maps SDK for Android : map-display ANR #102

zhangwenxiang26 opened this issue Jun 20, 2024 · 0 comments

Comments

@zhangwenxiang26
Copy link


SDK version:

def tom_version = "0.49.0"
implementation "com.tomtom.sdk.maps:map-display:$tom_version"
implementation "com.tomtom.sdk.location:provider-android:$tom_version"
implementation "com.tomtom.sdk.routing:route-planner-online:$tom_version"
implementation "com.tomtom.sdk.search:search-online:$tom_version"

model :
SM-A5160 Android 13


1.Problem description :

  • My Application has two activities: MainActivity and TomtomMapActivity;
  • MainActivity: used to jump to TomtomMapActivity;
  • TomtomMapActivity: used to display Tomtom maps;
  • After jumping from MainActivity to TomtomMapActivity, quickly pan or zoom the map. When the map data is not yet fully rendered, immediately return to the previous page of MainActivity and finish TomtomMapActivity. Then my Application will experience ANR and cannot perform any operations.

2.The code is as follows:

class MainActivity : AppCompatActivity() {
lateinit var vb: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    vb = ActivityMainBinding.inflate(getLayoutInflater())
    setContentView(vb.root)

    vb.btnSecond.setOnClickListener {
        startActivity(Intent(this@MainActivity, TomtomMapActivity::class.java))
    }
}

}

class TomtomMapActivity : AppCompatActivity() {
private lateinit var vb : ActivityTomtomMapBinding
private lateinit var mapShow :TomMapControl
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
vb = ActivityTomtomMapBinding.inflate(layoutInflater)
setContentView(vb.root)

    vb.flBack.setOnClickListener {
        finish()
    }

    mapShow = TomMapControl()
    mapShow.showTomMap(this,vb.flMap)

}

override fun onDestroy() {
    mapShow.clearMapRes()
    super.onDestroy()
}

}


class TomMapControl {
private var mTomtomMap: TomTomMap? = null
private var tomtomMapFragment: MapFragment? = null
private var mActivity: FragmentActivity? = null
private var mapContain: FrameLayout? = null
private val defualtLocation: GeoPoint = GeoPoint(22.357942, 106.845056)
private val DEFAULT_ZOOM = 17.0
fun showTomMap(
activity: FragmentActivity?,
frameLayout: FrameLayout?
) {
if (activity == null || frameLayout == null) {
return
}
mActivity = activity
frameLayout.removeAllViews()
mapContain = frameLayout
val fm = activity.supportFragmentManager
val transaction = fm.beginTransaction()
tomtomMapFragment = MapFragment.newInstance(getMapOptions()).apply {
transaction.replace(frameLayout.id, this)
transaction.commit()
getMapAsync {
onMapReady(it)
}
}
}

fun clearMapRes() {
    mActivity = null
    mapContain?.removeAllViews()
    mapContain = null
    mTomtomMap?.clear()
    mTomtomMap = null
}

fun onMapReady(map: TomTomMap) {
    mTomtomMap = map
    initMapConfig()
}

private fun initMapConfig() {
    hideBuiltInUiControls()
    enableDisableGestures()
}

private fun enableDisableGestures(){
    mTomtomMap?.isTiltEnabled = false
    mTomtomMap?.isRotationEnabled = false
}

private fun hideBuiltInUiControls() {
    tomtomMapFragment?.apply {
        currentLocationButton.visibilityPolicy =
            CurrentLocationButton.VisibilityPolicy.Invisible 
        logoView.visibilityPolicy = LogoView.VisibilityPolicy.Invisible //logo
        scaleView.isVisible = false
        zoomControlsView.isVisible = false
    }
}

private fun getMapOptions(): MapOptions {
    val key = BuildConfig.tomtomKey
    val cameraOptions = CameraOptions(position = defualtLocation, zoom = DEFAULT_ZOOM)
    val mapOptions = MapOptions(
        mapKey = key,
        cameraOptions = cameraOptions,
        styleMode = StyleMode.MAIN
    )
    return mapOptions
}

}


3.I need help, how can I solve the ANR situation described above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant