【发布时间】:2016-04-12 21:45:34
【问题描述】:
我正在尝试制作一个 100% 的时间在后台运行的优化应用程序。 它接收位置更新并将其发布到服务器。
我想知道我是否按照我应该的方式做事。
此时我的应用程序有一个使用 LocationServices API 请求LocationUpdates 的服务。 它会累积位置并尝试将它们发送到服务器。
如果没有更多位置待定,则此服务将自行终止。
我还有一个闹钟可以每隔一段时间唤醒这个服务。
所以下次服务唤醒时,启动一个新的 GooglePlayServices 会话并再次接收位置。
我知道使用pendingIntents 对非托管位置跟踪更好,但我仍然认为需要后台服务及时上传位置。
- 我应该停止使用警报服务吗?
- 有没有什么方法可以在没有用户干预/活动的情况下开始请求位置更新?
- 广播接收器是否能够管理网络发布等繁重的工作?
从 google locationServices 文档获得this:
public abstract PendingResult<Status> requestLocationUpdates
(GoogleApiClient client, LocationRequest request, PendingIntent
callbackIntent)
使用指定回调请求位置更新 待定意图。
此方法适用于后台用例,更具体地说 用于接收位置更新,即使应用程序已被 系统。为此,请使用 PendingIntent 来启动 服务。对于前台用例,LocationListener 版本的 推荐方法,见 requestLocationUpdates(GoogleApiClient, LocationRequest,LocationListener)。
提前致谢
【问题讨论】:
标签: android service android-pendingintent location-services