tags:

views:

322

answers:

1

In blackberry, we use a timeout to get the location, so that if it doesnt retun location in that much time period, we get to know. But in Android, there is no concept of timeout, can anyone please tell the alternative, that we can find out that after this much time there is no location update from GPS.

+1  A: 

You can use two threads for this timeout. One thread tries to get the GPS fix and the other (timeout) thread, once it reaches the timeout specified, removes the registration of your application to receive location updates from the location listener.

Prashast
but i am using requestLocationUpdates() and i will get location only in onLocationChanged(), it is here, where i want to know that if i don't get a fix within say 1 minutes, then i should stop the listener.how can I do that?Thanks
Farha Ansari
Create a TimeoutListener interface which the timeout thread callsback after it times out.Lets say you are calling the requestLocationUpdate from the Activity A. Make Activity A implement the TimeoutListener. Pass Activity A to the timeout thread which will then make a callback to the Activity using the interface. In your callback function you can stop receiving location updates.
Prashast
can anyone please share with me the code for it. i really can't understand how to go about it.Thanks.
Farha Ansari
i m using a background service
Farha Ansari