Check whether the attached context is finishing before attempting to
dismiss the dialog and use null propagation to access the dialog, just in
case there are any race conditions.
I ran into this issue when using aritchie/userdialogs in a xamarin forms app. If another activity has focus, such as the photo library, then the progress dialog seems to be unable to associate itself with our application's activity properly. When it is eventually dismissed the exception is thrown. There is an additional check to determine if the activity is already destroyed, but is only available in a higher API version.
Check whether the attached context is finishing before attempting to dismiss the dialog and use null propagation to access the dialog, just in case there are any race conditions.
I ran into this issue when using aritchie/userdialogs in a xamarin forms app. If another activity has focus, such as the photo library, then the progress dialog seems to be unable to associate itself with our application's activity properly. When it is eventually dismissed the exception is thrown. There is an additional check to determine if the activity is already destroyed, but is only available in a higher API version.
P.S. Sorry about the whitespace differences