通过Android中的服务获取GPS位置 [英] Get GPS location via a service in Android
问题描述
我需要使用后台服务来监控用户的位置,然后加载它们并显示给用户的路径。
使用一项活动很容易获取GPS位置,但是当我通过服务完成时,我遇到了一个问题,因为它似乎只适用于looper线程(或类似的东西)。
当我在互联网上搜索解决方案时,发现许多人遇到了同样的问题,但我找不到可行的解决方案。有些人说你需要使用prepare-> loop-> quit,有人说你必须使用handlerThread,但是我仍然不知道如何以适当的方式做这些事情。
好的,我通过在服务的onCreate上创建一个处理程序并通过那里调用gps函数来解决它。
I need to monitor user's locations using a background service, and then load them and show the path to the user.
Using an activity, it was quite easy to get GPS locations, but when I got to do it via a service, I came into a problem as it seems to only work for looper threads (or something like that).
As I've searched the internet for a solution, I've found out that many people got the same problem, but I couldn't find a working solution. Some people say that you need to use prepare->loop->quit , and some say you have to use a handlerThread, but still, I can't find out how to do such things in a proper way.
ok , i've solved it by creating a handler on the onCreate of the service , and calling the gps functions through there .
这篇关于通过Android中的服务获取GPS位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!