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.
Just complementing, I implemented this way and usually worked in my Service class
In my Service
I don't understand what exactly is the problem with implementing location listening functionality in the Service. It looks pretty similar to what you do in Activity. Just define a location listener and register for location updates. You can refer to the following code as example:
Manifest file:
The service file:
ok , i've solved it by creating a handler on the onCreate of the service , and calling the gps functions through there .