From 86a2a765b9b7bea005bafaad5a4489f06a151de3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 25 Jul 2020 11:19:53 +0200 Subject: fix memory leak --- .../leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java index 0a2e2538..890d3b67 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java @@ -22,6 +22,8 @@ import android.content.Intent; import android.os.Bundle; import android.util.Log; +import java.lang.ref.WeakReference; + import se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState; /** @@ -33,18 +35,18 @@ import se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState; */ public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver { - private final ProviderSetupInterface setupInterface; + private WeakReference setupInterfaceRef; public ProviderApiSetupBroadcastReceiver(ProviderSetupInterface setupInterface) { - this.setupInterface = setupInterface; + this.setupInterfaceRef = new WeakReference<>(setupInterface); } @Override public void onReceive(Context context, Intent intent) { Log.d(ProviderListBaseActivity.TAG, "received Broadcast"); - + ProviderSetupInterface setupInterface = setupInterfaceRef.get(); String action = intent.getAction(); - if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT)) { + if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT) || setupInterface == null) { return; } -- cgit v1.2.3