From cda80f5de654b913906a53b5d1d2e3d6669b5139 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 13 Mar 2015 10:22:06 +0100 Subject: [PATCH] Register ContentObserver when activity is started The ContentObserver was registered only when the activity was in resumed state. However, in started but paused state (when the activity is visible but not in focus), we still want to receive these notifications to update the view. Therefore, register it on start and unregister it on stop. As a consequence, myAppObserver will be non-null during onActivityResult(). --- F-Droid/src/org/fdroid/fdroid/AppDetails.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index 07b5fd079..5be3f9e23 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -468,15 +468,19 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A private String mInstalledSigID; @Override - protected void onResume() { - super.onResume(); - + protected void onStart() { + super.onStart(); // register observer to know when install status changes myAppObserver = new AppObserver(new Handler()); getContentResolver().registerContentObserver( AppProvider.getContentUri(app.id), true, myAppObserver); + } + + @Override + protected void onResume() { + super.onResume(); if (downloadHandler != null) { if (downloadHandler.isComplete()) { downloadCompleteInstallApk(); @@ -521,12 +525,14 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A } } + protected void onStop() { + super.onStop(); + getContentResolver().unregisterContentObserver(myAppObserver); + } + @Override protected void onPause() { super.onPause(); - if (myAppObserver != null) { - getContentResolver().unregisterContentObserver(myAppObserver); - } if (app != null && (app.ignoreAllUpdates != startingIgnoreAll || app.ignoreThisUpdate != startingIgnoreThis)) { Log.d(TAG, "Updating 'ignore updates', as it has changed since we started the activity...");