Skip to content

Commit b980248

Browse files
committed
Merge pull request #213 from robertbaker/patch-2
Fixes: System.InvalidOperationExceptionSequence
2 parents f606c51 + 0eaf2ff commit b980248

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

MvvmCross.Droid.Support.V7.Fragging/Caching/MvxCachingFragmentActivity.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,13 @@ public virtual bool Show(MvxViewModelRequest request, Bundle bundle, Type fragme
436436
public virtual bool Close(IMvxViewModel viewModel)
437437
{
438438
//Workaround for closing fragments. This will not work when showing multiple fragments of the same viewmodel type in one activity
439-
var frag = GetCurrentCacheableFragmentsInfo ().First (x => x.ViewModelType == viewModel.GetType());
440-
CloseFragment(frag.Tag, frag.ContentId);
441-
439+
var frag = GetCurrentCacheableFragmentsInfo ().FirstOrDefault (x => x.ViewModelType == viewModel.GetType());
440+
if (frag == null)
441+
{
442+
return false;
443+
}
442444
// Close method can not be fully fixed at this moment. That requires some changes in main MvvmCross library
445+
CloseFragment(frag.Tag, frag.ContentId);
443446
return true;
444447
}
445448
}
@@ -454,4 +457,4 @@ public abstract class MvxCachingFragmentActivity<TViewModel>
454457
set { base.ViewModel = value; }
455458
}
456459
}
457-
}
460+
}

0 commit comments

Comments
 (0)