android - MapBox 9.2.0 在 Android 8.0 (Oreo) JNI DETECTED ERROR IN APPLICATION 中导致崩溃
问题描述
没有问题,但是当它在 3 或 5 分钟后进入后台时,应用程序崩溃 JNI DETECTED ERROR IN APPLICATION: can't call java.lang.Object java.lang.ref.Reference.get() on instance java.lang.String 从 void android.os.MessageQueue.nativePollOnce(long, int) 调用 CallObjectMethodV,这就是它在日志中显示的内容。
class HomeFragment : BaseFragment() {
@Inject
lateinit var factory: ViewModelProvider.Factory
lateinit var binding: HomeBinding
var anchorClicked: Boolean = false
private lateinit var mapboxMap: MapboxMap
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = inflater.bind(R.layout.fragment_home, container)
return binding.root
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
binding.handler = this
binding.lifecycleOwner = viewLifecycleOwner
binding.mapView.onCreate(savedInstanceState)
val navigationView: NavigationView = requireActivity().findViewById(R.id.sideNV)
val headerView = navigationView.getHeaderView(0)
withViewModel<MapViewModel>(factory) {
binding.mapView.getMapAsync { mapBoxMap ->
this@HomeFragment.mapboxMap = mapBoxMap
if (getCurrentTheme())
mapBoxMap.setStyle(Style.TRAFFIC_NIGHT){
requestPermission(it)
}
else mapBoxMap.setStyle(Style.TRAFFIC_DAY){
requestPermission(it)
}
}
val auth = FirebaseAuth.getInstance()
if (auth.currentUser != null) {
val auth1 = FirebaseAuth.getInstance()
if (auth1.currentUser != null) {
headerView.userNameTV.text = auth1.currentUser?.displayName
headerView.userEmailTV.text = auth1.currentUser?.email.toString()
Glide.with(requireActivity())
.load(auth1.currentUser?.photoUrl)
.apply(RequestOptions.bitmapTransform(RoundedCorners(14)))
.into(headerView.userPicIV)
}
}
binding.vm = this
getCountries().observe(viewLifecycleOwner, Observer { })
}
}
fun requestPermission(style:Style) {
if (!hasPermissions(context, permissions)) requestPermissions(permissions, RC_LOCATION)
else enableLocationComponent(style)
}
private fun enableLocationComponent(loadedMapStyle: Style) {
val customLocationComponentOptions = LocationComponentOptions.builder(context!!)
.trackingGesturesManagement(true)
.accuracyColor(ContextCompat.getColor(context!!, R.color.com_facebook_blue))
.build()
val locationComponentActivationOptions =
LocationComponentActivationOptions.builder(context!!, loadedMapStyle)
.locationComponentOptions(customLocationComponentOptions)
.build()
mapboxMap.locationComponent.apply {
activateLocationComponent(locationComponentActivationOptions)
isLocationComponentEnabled = true
cameraMode = CameraMode.TRACKING
renderMode = RenderMode.COMPASS
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == RC_LOCATION) {
if (grantResults.isNotEmpty()
&& grantResults[0] == PackageManager.PERMISSION_GRANTED
) {
enableLocationComponent(mapboxMap.style!!)
}
}
}
companion object {
const val RC_LOCATION = 10
}
}
这是我的代码。这是奥利奥中的某种限制/地图框的问题。如果是这样,可以做些什么来避免这种情况。我们可以使用协程来解决这个问题吗?
解决方案
推荐阅读
- c++ - 如何在不破坏其父接口的情况下向对象添加属性?
- android - Google Play 上的 Android Auto 程序为我的申请提供了临时通行证
- android - 如何将 pwa 作为一个部分集成到现有的 android 和 ios 应用程序中?
- javascript - 在Angular中将*ngFor与异步管道一起使用时的无限循环
- batch-file - 使用 CMD 提取多个 zip 文件,无需第三方工具
- .net - 如何测试异步任务方法
- vba - 我正在尝试创建一个简单的用户表单,用于在 Word 中添加和删除文本块
- c++ - WriteFile 需要更多时间才能完成
- angular - 预期数量 预期茉莉花
- dialogflow-es - 模拟期间未找到 GSI 帐户关联