即使手机处于 sleep 状态,我也需要在后台通过 GPS 更新位置。我正在考虑使用 AlarmManager 广播一个 Intent,然后接收器将调用 LocationManager 上的 requestLocationUpdates()。但是我不确定如果我在调用 requestLocationUpdates() 时注册了 PendingIntent,是否可以保证在手机处于 sleep 状态时更新 GPS 位置并广播 intent?
谢谢,
最佳答案
你可以使用 service .
A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class.
如果您的手机进入休眠状态,该服务将在后台继续工作。请记住使用 startService() 启动服务而不是 bindService()否则,当启动服务的 Activity 进入休眠状态时,服务将停止。
希望这对您有帮助..
关于Android:手机处于 sleep 状态时GPS位置更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3010011/