KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Edit: I'm rewriting this question because I apparently wasn't clear. Sometimes the GPS service on Android phones takes a long time to get a fix. Sometimes it's fast, sometimes it takes hours. I know and accept this. I have an application that does many things. One of the things it must do is allow the user to click a button to send their current coordinates to a server. What I need are the coordinates of the phone when the user clicks the button or within a reasonably short time thereafter. Because I know that getting a GPS fix is not instant and I know that it could take minutes or hours (during which the user has moved a great distance), I need to code a timeout for this feature. For this feature, it is simply not acceptable to upload the GPS location of the user three minutes (for example) after they clicked the button. It's fine if it takes 45 seconds, not okay if it takes 75 seconds. It's fine to give the user an error notification if the feature failed to get a location fast enough. I need a feature to 'get the GPS location and send it to the server, unless it takes more than one minute '. My original code is below. I have changed some things since posting it. I have added a Timer in the onStartCommand() method. I start a TimerTask that after 60 seconds will call my stop() method. At the beginning of the onLocationChanged() method, I cancel the TimerTask. My question is: Is the Timer scheme a good way of implementing this timeout? Is there a better way? Original question: I'm writing an Android application that, among other things, needs to send the current GPS coordinates to a server when the user tells it to. From a context menu, I run the service below. The service is a LocationListener and requests updates from the LocationManager. When it gets a location (onLocationChanged()), it removes itself as a listener and sends the coordinates off to the server. All of thi
Tags (comma-separated)
Save Edits
Cancel