From 1a1ece16cfb4b8cac9067aab03de6e551692c5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 9 Feb 2016 20:48:42 +0000 Subject: [PATCH] Work around dead activity issue in AppDetails It seems like install() sometimes runs when the AppDetails activity is finished or finishing. This results in the windows (dialogs) failing to show, and a BadTokenException to fire: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@d6e3570 is not valid; is your activity running? This seems to be the culprit: at org.fdroid.fdroid.AppDetails.install(AppDetails.java:840) at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.install(AppDetails.java:1657) at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.onListItemClick(AppDetails.java:1721) Apparently, you can check whether an activity/context is being finished: https://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running I cannot reproduce this issue, thus can't say whether this fixes it or not. Either way, it can't hurt to try. This can be reverted if we see ACRA reports of this in the future, and the issue reopened. Fixes #565. --- F-Droid/src/org/fdroid/fdroid/AppDetails.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index 561645b84..c1a3df1bc 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -798,6 +798,10 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A // Install the version of this app denoted by 'app.curApk'. @Override public void install(final Apk apk) { + if (isFinishing()) { + return; + } + // Ignore call if another download is running. if (downloadHandler != null && !downloadHandler.isComplete()) return;