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.
This commit is contained in:
Daniel Martí 2016-02-09 20:48:42 +00:00
parent 9195e3c614
commit 1a1ece16cf

View File

@ -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;