Take the 2-minute tour ×

In my android application I active the fix position with gps:

mLManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 30000, 0, mLListener);

so that every 30 seconds the GPS is active and looking for the position. What I would like is this: the gps is activated for the n-th time, and as I walked into a building fails to fix my position so he seeks the position indefinitely. Can I stop it if the position is not fixed in 60 seconds? how can I do that? Thanks in advance!

share|improve this question
By adding a timer –  meh Feb 19 at 15:19
add comment

1 Answer

public boolean getLocation(Context context) {
         mLManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 30000, 0,mLListener);
         timer1=new Timer();
         timer1.schedule(new GetLastLocation(), 60000);

         return true;

LocationListener mLListener = new LocationListener() {
         public void onLocationChanged(Location location) {

class GetLastLocation extends TimerTask {
        public void run() {

It looks for a location, if it didn't found any location, and the 60 secs expires, then the timer will and you can execute an action. if it does find a location, it will cancel the timer.

share|improve this answer
add comment

Your Answer


