- // Show the HTTP authentication dialog.
- httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+ // Try to show the dialog. WebView can receive an HTTP authentication request even after the app has been paused. Attempting to display a dialog in that state leads to a crash.
+ try {
+ // Show the HTTP authentication dialog.
+ httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+ } catch (exception: Exception) { // The dialog could not be shown.
+ // Add the dialog to the pending dialog array list. It will be displayed in `onStart()`.
+ pendingDialogsArrayList.add(PendingDialogDataClass(httpAuthenticationDialogFragment, getString(R.string.http_authentication)))
+ }