Android LocationManager ignores changes to requestLocationUpdates calls, but only on Droid

In the Android app I'm developing, I need the LocationManager to give me location fixes. This part is good and good; It works, it has been quite a long time, and everyone there is happy.

However, now that I have also recently added a feature that allows the location tracking part to go to the background, I also want it to slow down updates in this case in order to save battery power. In fact, the way I'm trying to do this is to call requestLocationUpdates again with new parameters if my background service detects that there are no more registered listeners (it provides something in the notification bar, so I still want it to receive updates ) Let me call this service "Servicemajig". The way I do this is shorter:

private void setMode(boolean foreground) {
    // This sets whether we're in foreground or background mode.  If we're
    // not changing anything, though, don't do anything.
    if(foreground == mForeground) return;

    // Set the current mode...
    mForeground = foreground;

    // ...and switch!
    if(mForeground) {
        // Foreground mode means we go full tilt.
        Log.i(DEBUG_TAG, "Switching to foregroud mode...");
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, Servicemajig.this);
    } else {
        // Background mode means we slow down.  Like, say, 30 seconds.
        Log.i(DEBUG_TAG, "Switching to background mode...");
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, Servicemajig.this);
    }
}

, . (.. , ), Nexus One G1 . , 30 ( ), , .

, Motorola Droid. Droid , , 30 ( , ) , , . , , , , 30 , , Servicemajig . , , , , .

, : , Droid? , ? - ? , , removeUpdates if registerLocationUpdates.

+3
1

, -. , Droid, . , , , . ( /) .

0

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


All Articles