question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] showModal : Cannot remove Fragment attached to a different FragmentManager

See original GitHub issue

Using rc version and @nativescript/core i am facing an issue with modal views. To counter that isssue https://github.com/NativeScript/NativeScript/issues/7744 i need to wrap my modal views inside a Frame Something like this

<Frame>
        <Page actionBarHidden ref="page">
            <StackLayout class="page" height="100%">
            </StackLayout>
        </Page>
    </Frame>

But now it crashes on Android when closing the modal with this error:

System.err: Error: java.lang.IllegalStateException: Cannot remove Fragment attached to a different FragmentManager. Fragment fragment2[2]<Page(65)> is already attached to a FragmentManager.
System.err: 
System.err: StackTrace:
System.err: Frame.disposeCurrentFragment(file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:27493:17)
System.err:     at Frame.onUnloaded(file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:27475:10)
System.err:     at (file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:20445:20)
System.err:     at ViewBase.callFunctionWithSuper(file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:20426:5)
System.err:     at ViewBase.callUnloaded(file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:20444:10)
System.err:     at DialogFragmentImpl.onDismiss(file:///data/data/com.microoled.activelook.mobile/files/app/vendor.js:22626:15)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)

I think the issue comes indeed from the fact that the manager used to opened the modal window https://github.com/NativeScript/NativeScript/blob/cc97a1680009f1bf6dbf97c421f6e8dc535295b5/nativescript-core/ui/core/view/view.android.ts#L657 is not the same as the one used in disposeCurrentFragment
https://github.com/NativeScript/NativeScript/blob/cc97a1680009f1bf6dbf97c421f6e8dc535295b5/nativescript-core/ui/frame/frame.android.ts#L260 which gets the FragmentManager here https://github.com/NativeScript/NativeScript/blob/cc97a1680009f1bf6dbf97c421f6e8dc535295b5/nativescript-core/ui/core/view/view.android.ts#L339

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
farfromrefugcommented, Nov 22, 2019

@JuanDeLeon i keep on modyfing the node modules files for now 😒

3reactions
farfromrefugcommented, Nov 13, 2019

Actually found the reason for the bug and it is not what i thought. The issue is with Frame calling super.onUnloaded before disposeCurrentFragment https://github.com/NativeScript/NativeScript/blob/cc97a1680009f1bf6dbf97c421f6e8dc535295b5/nativescript-core/ui/frame/frame.android.ts#L250

Doing so _manager is set to null but then after in disposeCurrentFragment, a call to this._getFragmentManager is made. At that point there is _manager anymore and so the root manager is returned. Inversing the order in Frame.onUnloaded solves the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why I am getting "Cannot remove Fragment attached to a ...
This would means that if the Fragment you are trying to access is associated with another Activity 's FragmentManager , then your app...
Read more >
Cannot remove Fragment attached to a different ...
Cannot remove Fragment attached to a different FragmentManager ... If the Fragment haven't been destroyed, then on popBackStack() the onStart() and onResume() ...
Read more >
FragmentTransaction.replace can not remove all the old ...
steps: 1.click one button to add 7 fragments in the container, 2.click another button to replace fragment according to container id.
Read more >
Why I am getting “Cannot remove Fragment attached to a ...
IllegalStateException : Cannot remove Fragment attached to a different FragmentManager. I have a separate fragment for fetching user's current location.
Read more >
Fragment manager - Android Developers
In other words, the transaction is reversed. If there are no more fragment transactions on the stack, and if you aren't using child...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found