- DialogFragment saveDialogFragment = SaveWebpageDialog.saveWebpage(saveType, urlString, fileStringArray[0], fileStringArray[1], userAgent, cookiesEnabled);
-
- // Show the save dialog. It must be named `save_dialog` so that the file picker can update the file name.
- saveDialogFragment.show(fragmentManager, activity.getString(R.string.save_dialog));
+ DialogFragment saveDialogFragment = SaveDialog.saveUrl(urlString, fileStringArray[0], fileStringArray[1], userAgent, cookiesEnabled);
+
+ // Try to show the dialog. Sometimes the window is not active.
+ try {
+ // Show the save dialog. It must be named `save_dialog` so that the file picker can update the file name.
+ saveDialogFragment.show(fragmentManager, activity.getString(R.string.save_dialog));
+ } catch (Exception exception) {
+ // Add the dialog to the pending dialog array list. It will be displayed in `onStart()`.
+ MainWebViewActivity.pendingDialogsArrayList.add(new PendingDialog(saveDialogFragment, activity.getString(R.string.save_dialog)));
+ }