summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorPablo Guardiola <guardiola31337@gmail.com>2017-02-07 17:15:20 +0100
committerGitHub <noreply@github.com>2017-02-07 17:15:20 +0100
commit3916090a241d0f2e31ad0a781cd69a014ac92011 (patch)
tree8ecdf50ce1a78b7fe4fb4cd5bc67ca5f4f6dbdd9 /platform
parent9279b198df7c1c9e93f3c2af2a7104d4a30367a8 (diff)
downloadqtlocation-mapboxgl-3916090a241d0f2e31ad0a781cd69a014ac92011.tar.gz
hold a weak reference of the context to avoid leaks (#7964)
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java
index ff367abe1f..0f3d013043 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java
@@ -13,6 +13,8 @@ import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LocationServices;
import com.mapzen.android.lost.api.LostApiClient;
+import java.lang.ref.WeakReference;
+
/**
* Manages locational updates. Contains methods to register and unregister location listeners.
* <ul>
@@ -36,13 +38,13 @@ public class LocationSource extends LocationEngine implements
private static LocationEngine instance;
- private Context context;
+ private WeakReference<Context> context;
private LostApiClient lostApiClient;
public LocationSource(Context context) {
super();
- this.context = context;
- lostApiClient = new LostApiClient.Builder(context)
+ this.context = new WeakReference<>(context);
+ lostApiClient = new LostApiClient.Builder(this.context.get())
.addConnectionCallbacks(this)
.build();
}
@@ -88,7 +90,7 @@ public class LocationSource extends LocationEngine implements
@Override
public Location getLastLocation() {
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
+ if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
//noinspection MissingPermission
return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
}
@@ -114,7 +116,7 @@ public class LocationSource extends LocationEngine implements
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
+ if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
}