Android Question Log phone's location and time every X minute and save to CSV file?

dadelayer

New Member
I am currently following this tutorial here: https://www.b4x.com/android/forum/threads/background-location-tracking.99873/

I'm trying to make a simple app where the user clicks on a button to start the tracking service, and then every X-minutes, the dateTime/location will be saved to a CSV file (append).
If the user stops the tracking service before the X-minute is up, then the current time/location will be saved in the log.
Once the user clicks stop (I guess I call the sub Service_Destroy?), the result is saved into an excel file.

The StringUtils.SaveCSV function accepts a table, I'm not quite sure how to get the DateTime/Location into a table that it'll accept.

What I have done so far is edited this project here so that the tracking is started when the button is pressed. Then, when the button is pressed again, I call the sub Service_Destroy. Not sure how to destroy the notification as well though.

Sorry if what I'm asking for is dumb, I'm 100% new to Android Dev. I know VB6/VB.NET but this isn't as similar
 

edgar_ortiz

Active Member
Licensed User
Longtime User
To understand your problem it is good that you attach the project (File - Export as Zip) or at least show the code you use
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Never call Service_Destroy yourself. Call StopService(Tracker).

The StringUtils.SaveCSV function accepts a table, I'm not quite sure how to get the DateTime/Location into a table that it'll accept.
I wouldn't use this for your case as you want to append more data to the same file.

Better to open the file in append mode File.OpenOutput(..., ..., True) and use TextWriter to add a line with the new data.
You can store the location time in a global long variable and compare it to the current time and only write the new location if X seconds have passed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…