Android: GPS location updates when the cellphone is in sleep?

拜拜、爱过 提交于 2019-12-04 16:55:26

GPS aren't working when screen is off! You may set alarm for you app, but to get GPS position you must make screen on.

Updated at 2016-08-23:

Please be note, this answer is old and this information not actual for last os versions.

You could use a 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.

If your phone go to sleep the service will continue its work in background. Remember to start the service using startService() instead of bindService() otherwise when the activity that start the service go to sleep the service will be stopped.

hope this helps..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!