diff --git a/fragmentation/src/main/java/com/weikaiyun/fragmentation/TransactionDelegate.java b/fragmentation/src/main/java/com/weikaiyun/fragmentation/TransactionDelegate.java index 6abec61..d6a050f 100644 --- a/fragmentation/src/main/java/com/weikaiyun/fragmentation/TransactionDelegate.java +++ b/fragmentation/src/main/java/com/weikaiyun/fragmentation/TransactionDelegate.java @@ -266,17 +266,21 @@ boolean dispatchBackPressedEvent(ISupportFragment activeFragment) { } void handleResultRecord(Fragment from) { - Bundle args = from.getArguments(); - if (args == null) return; - final ResultRecord resultRecord = args.getParcelable(FRAGMENTATION_ARG_RESULT_RECORD); - if (resultRecord == null) return; - - ISupportFragment targetFragment = (ISupportFragment) from - .getParentFragmentManager() - .getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT); - - if (targetFragment == null) return; - targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle); + try { + Bundle args = from.getArguments(); + if (args == null) return; + final ResultRecord resultRecord = args.getParcelable(FRAGMENTATION_ARG_RESULT_RECORD); + if (resultRecord == null) return; + + ISupportFragment targetFragment = (ISupportFragment) from + .getParentFragmentManager() + .getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT); + + if (targetFragment == null) return; + targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle); + } catch (IllegalStateException ignored) { + // Fragment no longer exists + } } private void enqueue(FragmentManager fm, Action action) {