X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FPrepareSaveDialog.java;h=d858f1cba98127b34aefd1cbbf4410afb64410a1;hp=9e8b1fd83b39d4e366afdbdc10e1582a3fe6eba6;hb=d4f39c36beb5e6c3568a1e075274ad66defd8e8e;hpb=f825cc15f0383acce10bb16443e027edb869a11e diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java index 9e8b1fd8..d858f1cb 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PrepareSaveDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Soren Stoutner . + * Copyright © 2020-2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -41,14 +41,14 @@ import java.text.NumberFormat; public class PrepareSaveDialog extends AsyncTask { // Define weak references. - private WeakReference activityWeakReference; - private WeakReference contextWeakReference; - private WeakReference fragmentManagerWeakReference; + private final WeakReference activityWeakReference; + private final WeakReference contextWeakReference; + private final WeakReference fragmentManagerWeakReference; // Define the class variables. - private int saveType; - private String userAgent; - private boolean cookiesEnabled; + private final int saveType; + private final String userAgent; + private final boolean cookiesEnabled; private String urlString; // The public constructor. @@ -198,6 +198,17 @@ public class PrepareSaveDialog extends AsyncTask { return; } + // Prevent the dialog from displaying if the app window is not visible. + // The asynctask continues to function even when the app is paused. Attempting to display a dialog in that state leads to a crash. + while (!activity.getWindow().isActive()) { + try { + // The window is not active. Wait 1 second. + wait(1000); + } catch (InterruptedException e) { + // Do nothing. + } + } + // Instantiate the save dialog. DialogFragment saveDialogFragment = SaveWebpageDialog.saveWebpage(saveType, urlString, fileStringArray[0], fileStringArray[1], userAgent, cookiesEnabled);