LocationManager requestLocationUpdates and timertask in android

I have the following code:

if (gps_enabled) {
        Log.e("$$$$$$$$$$$$$$",
                "GPS is enabled requestion location updates... interval value is: "
                        + interval);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                locationListenerGps);
    }
    else{
        if (network_enabled) {
            Log.e("$$$$$$$$$$$$$$",
                    "Network is enabled requestion location updates... interval value is: "
                            + interval);
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,
                    0, locationListenerNetwork);
        }
    }

with this code I can get the location (at least using the network provider! (another problem in another message)) I would like to receive notifications in the regular interval every one hour, but passing the requestLocationUpdates parameter does not guarantee that the interval will be maintained (at least to the extent that my tests showed, since I was expecting an update every minute, but got a lot of updates instead of one!) so I thought about using timerTask and schedule it, now I have

timer1.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            getLocation();
        }

    }, 0, 180000);// 3 minutesr...

where getLocation is the method that I called the previously called, but when the timer calls this method, nothing happens, the logs stop at this point

Log.e("$$$$$$$$$$$$$$",
                    "Network is enabled requestion location updates... interval value is: "
                            + interval);

. ?

+3
1

Ok , , , , , , .

+7

Source: https://habr.com/ru/post/1762039/


All Articles