From 3ad429aa6b9583581b4cb5e8f0c6796ea72ff152 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Sat, 10 Oct 2015 08:52:14 +1100 Subject: [PATCH] Guard against null activity. Came across this whibluetooth swap. I think it is reasonable to guard against null activities here, because we are likely not releasing observers correctly, and thus the observer may receieve a notification when the activity is not attached. --- .../src/org/fdroid/fdroid/views/swap/SwapAppsView.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java index c69bee088..aee3a3a46 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java @@ -1,6 +1,7 @@ package org.fdroid.fdroid.views.swap; import android.annotation.TargetApi; +import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -330,9 +331,12 @@ public class SwapAppsView extends ListView implements private final ContentObserver appObserver = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { - app = AppProvider.Helper.findById(getActivity().getContentResolver(), app.id); - apkToInstall = null; // Force lazy loading to fetch correct apk next time. - resetView(); + Activity activity = getActivity(); + if (activity != null) { + app = AppProvider.Helper.findById(getActivity().getContentResolver(), app.id); + apkToInstall = null; // Force lazy loading to fetch correct apk next time. + resetView(); + } } };