gpt4 book ai didi

Android OnlocationChanged 停止被调用

转载 作者:行者123 更新时间:2023-12-04 23:51:29 27 4
gpt4 key购买 nike

当程序在前台运行时,它工作正常。只有当某些其他应用程序在前台运行并且我的程序在后台运行时,onlocationchanged 才会停止调用。

这不会立即发生,但在将应用程序切换到后台后仍会相对较快。说,在几秒钟内到可能长达几分钟。

现在,当 onlocationchanged 函数停止被调用时,当持有 onlocationchanged 代码的应用程序切换回前台时,它将再次调用它。

我拥有的唯一代码在 oncreate 方法和 onlocationchanged 方法中。其他方法,如 onresume、onpause、onproviderdisabled、onproviderenabled 仅包含一行记录调用的日志。当 onlocationchanged 函数停止被调用时,这些函数都不会被调用。

这是我用来创建 locationmanager 对象的代码:

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

最佳答案

我知道我回答迟了,但是当我遇到同样的问题时我找到了解决方案。
您的解决方案:
Background location access checklist

If your app targets Android 10 (API level 29) or higher, also check for the ACCESS_BACKGROUND_LOCATION permission. Verify that your app has a feature that requires it.

关于Android OnlocationChanged 停止被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28332160/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com