Android Smart Location Library always connects to gps after closing the application

I am developing an application that launches a user's location. I use Smart Location Library to get location and reverse geocode. But the main problem is that the GPS is connected, showing a notification, even after closing the application. I checked the stack trace, but there was no exception detected from the window. I use this code to get my location.

private void getMyLocation(){
    final long mLocTrackingInterval = 1000000 * 5; // 5 sec
    float trackingDistance = 1000 * 10;
    LocationAccuracy trackingAccuracy = LocationAccuracy.HIGH;
    LocationParams.Builder builder = new LocationParams.Builder()
                .setAccuracy(trackingAccuracy)
                .setDistance(trackingDistance)
                .setInterval(mLocTrackingInterval);
    SmartLocation.with(mContext)
                .location(provider)
                // .continuous()
                .oneFix()
                .config(builder.build())
                .start(this);
}

@Override
public void onLocationUpdated(Location location) {
    SmartLocation.with(mContext).geocoding()
            .reverse(location,new OnReverseGeocodingListener() {
                @Override
                public void onAddressResolved(Location location, List<Address> results) {
                    if (results.size() > 0) {
                        mAddressList=results;
                        mLocation=location;
                        tvLocation.setText( results.get(0).getAddressLine(0)+"\n"+results.get(0).getAddressLine(1));
                    }
                }
            });
}

And onStop()the main activity method.

@Override
protected void onStop() {
    super.onStop();
    SmartLocation.with(mContext).location(provider).stop();
    SmartLocation.with(mContext).geocoding().stop();
}

Edit

I am using this povider. I also tried other providers. But all the same result.

private LocationGooglePlayServicesWithFallbackProvider provider=new LocationGooglePlayServicesWithFallbackProvider(mContext);

I tried a lot, but I can not understand what the problem is. Any help would be appreciated. thank

+4
1

, Async. . , , , . . MainActivity.java. onActivityResult() - , .

, ? ...

? , Android. . Android . , onStop() , , . onStop(), , . , onPause(), - .

, GPS, ( , ), onPause(). - :

@Override
protected void onPause() {
    super.onPause();

    if (SmartLocation == still_running) { // pseudo code
        SmartLocation.with(mContext).location(provider).stop();
        SmartLocation.with(mContext).geocoding().stop();
    }
}
+2

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


All Articles