-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add note about Android control parenting when control already has a parent #1923
Comments
This also happens on Windows. Might be worth stating that you should always do it... |
I am having this issue when switching between two control templates in a TemplatedView. In my case, the parent is always the same, just based on a condition I show one control template or another one. So, i am a bit confused about the exception. |
UPDATE: 26042024 please ignore this comment, I updated to maui 8.0.21 and now Is working well in windows and android, by not using the work around of setting the parent to null i also fixed a memory leak i had been hunting down Important noteWhy is this a dulicate of issue 15920 and 20310? why are they close? Have they been solved in a PR or merge that I missed? why are they only tagged as android? ContextI have hit this issue for weeks in my windows App (tested on win10 and android with and without debugging) and as you can see in the screenshots provided in some comments in 15920 the error raised in windows plataform "No installed componets were detected" was useless and the debugger was often crashing before even raising an error so I could not find any help or share my work around. Finally I decided to try other plataforms and it was in android that I found an error "Java.Lang.IllegalStateException: The specified child already has a parent" that lead to 15920 and 20310. IssueMy case was basically a grid of cells set as content of a control, the grid was made with a verticalStackLayout full of HorizontalStackLayouts full of my cuscomCellControls (going forwards cell). And it was crashing only if I reused the cells instead of creating a new instance. It is quite similar to 15920 and 20310 which both have in the issue itself and in some comments code to test it. Workaround:In my case setting the handler to null fixed the issue. In fact I recommend using the extension method CheckHandlers since its current implementation is setting the handler to null.
The method CheckHandlers with his current implementation seems a better option because it's covering more scenarios workarounds that are not working for meNeither setting the parent to null or getting the parent to remove the child seems to be solving the issue but they also dont affecting my workaround. |
This is motivated by this issue: dotnet/maui#15920
On Android you can't 'move' a control from one parent to another without first removing it from the first parent. This is different from other platforms where this is allowed.
The exception you get is
Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
I suggest updating the docs with the following:
removeView()
)cc @hartez
The text was updated successfully, but these errors were encountered: