jeudi 25 février 2016

how to request data periodically from phone Sensors via a service and load it to activity (Android)

I have an idea in mind which I got a bit confused about how to implement.

I want to make for practice some "running app": Basically a map, that gets your location when you start a running, and then draws polygones from location every X seconds (let's say x=2), calculates the distance from every polygone till the end and genreates some other details (that's not the problem).

question 1: How can I make the service save some data locatlly to each run? for example, I run for 60 seconds, got 30 Latlng objects and then I loop through them and then genrate the running details. Where can I save the Latlng objects, while the service is running? I thought about making a local DB using SQLite, then through a brodacast receiver I create an intent service that get the location and the current time, save it to local DB with the details and stop. (how can I know how much Latlngs I have on the local DB? I need to make some variable to identify it, how can I generate it each time I am calling the intent service?) is there any other ideas you can recommend me about to do that and store the LatLng? when I press the "stop running" I'll just look for the latlng from the DB and then delete it.

Question 2: If I am using an intent service to get the Latlng object of the current location, how can I draw a polygons at the same time on the map, in addition to the action of saving it to the local DB? ( I know Intent service cannot communicate with the UI directly. I got confused here a little bit)

I think my idea of implement and create this "mock" up is really a bad practice. If you have and ideas or places to reference me, I'll appreciate it. Thank you

Aucun commentaire:

Enregistrer un commentaire