-
Notifications
You must be signed in to change notification settings - Fork 0
Fragment already added Exception #204
Comments
I can reproduce this. Some more info:
We should probably check for something when poping the backstack, but i am not sure what currently. |
And another one: http://stackoverflow.com/questions/6250580/fragment-already-added-illegalstateexception I will do some tests on my side as soon as possible. |
Hi there, I've found a workaround that is acceptable for my application. public class MvxCachingFragmentCompatActivity : ....
{
private string _firstFragmentTag;
// ...
protected override void ShowFragment(string tag, int contentId, Bundle bundle, bool forceAddToBackStack = false, bool forceReplaceFragment = false)
{
// ...
if (fragmentReplaceMode == FragmentReplaceMode.ReplaceFragmentAndViewModel)
{
var cache = Mvx.GetSingleton<IMvxMultipleViewModelCache>();
cache.GetAndClear(fragInfo.ViewModelType, GetTagFromFragment(fragInfo.CachedFragment as Fragment));
}
//////////////////
// MODIFICATION
// Clear the backstack
if (fragInfo.Tag == _firstFragmentTag)
{
SupportFragmentManager.PopBackStack(null, (int)PopBackStackFlags.Inclusive);
}
//////////////////
// MODIFICATION
// Save the first fragment tag for further use
if (string.IsNullOrEmpty(_firstFragmentTag))
{
_firstFragmentTag = fragInfo.Tag;
}
// ...
}
} I assume here the application have a "HomeFragment" and using the back button from the HomeFragment whatever the navigation have been before, the application terminates. If this is a constraint acceptable, let me know, I'll push a PR. |
It seems acceptable to me, but i can't oversee the issue enough to know for sure. If you submit a PR i'll test it, and merge if everything works. |
@sescandell please make a pr |
@robertbaker Done, sorry for the delay |
Hi I am facing the same issue how can I overcome this in my application.In my application I am using a single activity and all the other screen are just fragments so when I click on one navigation drawer item and press back button and I do this twice then I get the above exception. How can I solve this since my application is crashing. |
Hi @glalwani2 You can create your own "FragmentBaseActivity" and override the |
Steps to reproduce
Expected behavior
The application should close when pressing back button when the HomeFragment is displayed.
Actual behavior
Application is crashing on call on
SupportFragmentManager.PopBackStackImmediate();
in MvxCachingFragmentCompatActivity fileConfiguration
Tested on Nexus 5 Android 6
Version:
master 2016-04-03.
Same behavior on 4.1.0
The text was updated successfully, but these errors were encountered: