You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Android] showModal : Cannot remove Fragment attached to a different FragmentManager #8037
Using rc version and @nativescript/core i am facing an issue with modal views.
To counter that isssue #7744 i need to wrap my modal views inside a Frame
Something like this
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
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.
Any workarounds for this?
It's crashing on Android when I have my Modal open and then click on the OS back button.
My Modal content is wrapped inside a Frame as well.
Well I can confirm your solution seems to be working fine for me as well.
Edit: It is now causing an issue when picking an image using the nativescript-image-picker plugin... so I guess I should remove the Frame and redesign my Modals slightly.
The workaround seems to be working for our issue as well! We however have a different stacktrace which happens while closing a modal (NS6.2):
JS: ERROR Error: Uncaught (in promise): Error: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.util.SparseArray.put(int, java.lang.Object)' on a null object reference
JS: push.../node_modules/@nativescript/core/ui/frame/frame.js.Frame.disposeCurrentFragment(file:///node_modules/@nativescript/core/ui/frame/frame.js:198:0)
JS: at push.../node_modules/@nativescript/core/ui/frame/frame.js.Frame.onUnloaded(file:///node_modules/@nativescript/core/ui/frame/frame.js:182:0)
JS: at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:316:77)
JS: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callFunctionWithSuper(file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:305:0)
JS: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callUnloaded(file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:316:0)
JS: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.Vi...
is throwing Frame should not have a view. Use 'defaultPage' property instead. error
Feel free to try to reproduce in the repo above, so that we can further investigate.
@NathanWalker@NathanaelA@rigor789 i just stumbled this one again. _getFragmentManager is not consistent and create some issues.
The thing is that for a View lifecycle it does not always return the same result.
as a example with tabs:
open tabs => _getFragmentManager is found and used to instantiate the tabs
navigate to another page from a menu or something
the stored _getFragmentManager is cleared in onUnloaded but then after the tabs viewPager call destroyItem but then the _getFragmentManager does not return the same FragmentManager (not sure exactly why yet). Which creates an inconsistency and finishes in a crash.
I solved this in tabs and bottomnavigation plugins by using _getRootFragmentManager which always returns the same FragmentManager. However this is not the correct fix.
We should really find out what the "lifecycle" of our _getFragmentManager is and fix this once and for all.
Activity
farfromrefug commentedon Oct 30, 2019
Actually found the reason for the bug and it is not what i thought.
The issue is with
Framecallingsuper.onUnloadedbeforedisposeCurrentFragmentNativeScript/nativescript-core/ui/frame/frame.android.ts
Line 250 in cc97a16
Doing so
_manageris set to null but then after indisposeCurrentFragment, a call tothis._getFragmentManageris made. At that point there is_manageranymore and so the root manager is returned.Inversing the order in
Frame.onUnloadedsolves the issue.JuanDeLeon commentedon Nov 21, 2019
Any workarounds for this?
It's crashing on Android when I have my Modal open and then click on the OS back button.
My Modal content is wrapped inside a Frame as well.
farfromrefug commentedon Nov 22, 2019
@JuanDeLeon i keep on modyfing the node modules files for now :s
JuanDeLeon commentedon Nov 22, 2019
Well I can confirm your solution seems to be working fine for me as well.
Edit: It is now causing an issue when picking an image using the nativescript-image-picker plugin... so I guess I should remove the Frame and redesign my Modals slightly.
bartsg commentedon Dec 2, 2019
The workaround seems to be working for our issue as well! We however have a different stacktrace which happens while closing a modal (NS6.2):
vakrilov commentedon Dec 3, 2019
I'm currently trying to investigate this issue in order to validate that the proposed solution does not break any other scenarios.
@farfromrefug and @bartsg can provide a repro project of the issue? I have tried (unsuccessfully) to reproduce the issue here: https://github.com/vakrilov/fragment-manager-crash. I had to separate the page and the frame into separate files as having the following xml:
is throwing
Frame should not have a view. Use 'defaultPage' property instead.errorFeel free to try to reproduce in the repo above, so that we can further investigate.
nikoTM commentedon Nov 3, 2020
@farfromrefug inverting the order as in calling
this.disposeCurrentFragment();thensuper.onUnloaded()?farfromrefug commentedon Nov 3, 2020
@nikoTM yes
nikoTM commentedon Nov 3, 2020
@farfromrefug did you notice any side effects with this move?
farfromrefug commentedon Apr 20, 2021
@NathanWalker @NathanaelA @rigor789 i just stumbled this one again.
_getFragmentManageris not consistent and create some issues.The thing is that for a
Viewlifecycle it does not always return the same result.as a example with tabs:
_getFragmentManageris found and used to instantiate the tabs_getFragmentManageris cleared inonUnloadedbut then after the tabs viewPager calldestroyItembut then the_getFragmentManagerdoes not return the same FragmentManager (not sure exactly why yet). Which creates an inconsistency and finishes in a crash.I solved this in tabs and bottomnavigation plugins by using
_getRootFragmentManagerwhich always returns the sameFragmentManager. However this is not the correct fix.We should really find out what the "lifecycle" of our
_getFragmentManageris and fix this once and for all.For reference:nativescript-community/ui-material-components#281