实现'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.0'
使用上述版本
class HomeFragment : BaseFragment() {
@Inject
lateinit var factory: ViewModelProvider.Factory
lateinit var binding: HomeBinding
private lateinit var mapboxMap: MapboxMap
lateinit var locationEngine: LocationEngine
lateinit var callback: LocationListeningCallback
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = inflater.bind(R.layout.fragment_home, container)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.handler = this
binding.lifecycleOwner = viewLifecycleOwner
callback = LocationListeningCallback(activity as MainActivity)
binding.mapView.onCreate(savedInstanceState)
withViewModel<MapViewModel>(factory) {
binding.vm = this
binding.mapView.getMapAsync { mapBoxMap ->
this@HomeFragment.mapboxMap = mapBoxMap
if (getCurrentTheme())
mapBoxMap.setStyle(Style.TRAFFIC_NIGHT) {
enableLocationComponent(it)
}
else mapBoxMap.setStyle(Style.TRAFFIC_DAY) {
enableLocationComponent(it)
}
}
}
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onStart() {
super.onStart()
mapView?.onStart()
}
override fun onStop() {
super.onStop()
mapView?.onStop()
}
override fun onPause() {
super.onPause()
mapView?.onPause()
}
override fun onLowMemory() {
super.onLowMemory()
mapView?.onLowMemory()
}
override fun onDestroyView() {
super.onDestroyView()
mapView?.onDestroy()
}
}
**仅当我们从包含mapview的片段更改为另一个片段时,才会发生此问题。**黑屏出现的时间约为2-3秒。 所有生命周期方法均已如上添加。感谢您的帮助。