[android] keep default file source alive for the duration (#8226)

This commit is contained in:
Ivo van Dongen
2017-03-01 08:33:51 -08:00
committed by Tobrun
parent 0027f5cdc2
commit 74d42a45e2

View File

@@ -9,8 +9,6 @@ import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import java.lang.ref.WeakReference;
import timber.log.Timber;
/**
@@ -36,19 +34,17 @@ public class FileSource {
}
// Use weak reference to avoid blocking GC on this reference.
// Should only block when mapview / Offline manager instances
// are alive
private static WeakReference<FileSource> INSTANCE;
// File source instance is kept alive after initialization
private static FileSource INSTANCE;
public static synchronized FileSource getInstance(Context context) {
if (INSTANCE == null || INSTANCE.get() == null) {
if (INSTANCE == null) {
String cachePath = getCachePath(context);
String apkPath = context.getPackageCodePath();
INSTANCE = new WeakReference<>(new FileSource(cachePath, apkPath));
INSTANCE = new FileSource(cachePath, apkPath);
}
return INSTANCE.get();
return INSTANCE;
}
public static String getCachePath(Context context) {