Fix IllegalStateException (#1585)

Fragment may have detached and does not have parent fragment manager
This commit is contained in:
LoveSy 2022-01-30 12:57:57 +08:00 committed by GitHub
parent b4eed403e4
commit 8e6fba6852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -100,18 +100,21 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
if (result instanceof UnknownError) { if (result instanceof UnknownError) {
text = context.getString(R.string.compile_failed); text = context.getString(R.string.compile_failed);
} else { } else {
text = context.getString(R.string.compile_failed_with_info) + result.toString(); text = context.getString(R.string.compile_failed_with_info) + result;
} }
} else { } else {
text = context.getString(R.string.compile_done); text = context.getString(R.string.compile_done);
} }
CompileDialogFragment fragment = outerRef.get(); try {
if (fragment != null) { CompileDialogFragment fragment = outerRef.get();
fragment.dismissAllowingStateLoss(); if (fragment != null) {
var parent = fragment.getParentFragment(); fragment.dismissAllowingStateLoss();
if (parent instanceof BaseFragment) { var parent = fragment.getParentFragment();
((BaseFragment) parent).showHint(text, true); if (parent instanceof BaseFragment) {
((BaseFragment) parent).showHint(text, true);
}
} }
} catch (IllegalStateException ignored) {
} }
} }
} }