From 155c17e3ee624719f19245c7108b75e246d87cd4 Mon Sep 17 00:00:00 2001 From: weikaiyun Date: Tue, 15 Sep 2020 20:20:33 +0800 Subject: [PATCH] bugfix --- .../fragmentation/TransactionDelegate.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) 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) {