Skip to content
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

[regression/8.0.0-preview.3.8149] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) #16499

Closed
tranb3r opened this issue Aug 2, 2023 · 10 comments · Fixed by #17353
Labels
area-controls-toolbar ToolBar fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! high It doesn't work at all, crashes or has a big impact. i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@tranb3r
Copy link

tranb3r commented Aug 2, 2023

Description

When using NavigationPage.TitleView, an app crashes when being launched again after it has been killed by the system.
Here is the exception: Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

Steps to Reproduce

  1. in android settings, developer options, enable "don't keep activites"
  2. launch test app, then tap on home button: app goes to background, and is killed by system
  3. launch app again, it crashes

Link to public reproduction project repository

Repro

Version with bug

8.0.0-preview.3.8149

Last version that worked well

8.0.0-preview.2.7871

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
   at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* )
   at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String , IJavaPeerable , JniArgumentValue* )
   at Android.Views.ViewGroup.AddView(View )
   at Microsoft.Maui.Controls.Toolbar.UpdateTitleView()
   at Microsoft.Maui.Controls.Toolbar.MapTitleView(IToolbarHandler , Toolbar )
   at Microsoft.Maui.Controls.Toolbar.MapTitleView(ToolbarHandler arg1, Toolbar arg2)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.Controls.Toolbar, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.ToolbarHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String , IElementHandler , IElement )
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler , IElement )
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement )
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement , IMauiContext )
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement , IMauiContext )
   at Microsoft.Maui.Handlers.ViewHandler.MapToolbar(IElementHandler , IToolbarElement )
   at Microsoft.Maui.Handlers.WindowHandler.MapToolbar(IWindowHandler handler, IWindow view)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String , IElementHandler , IElement )
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler , IElement )
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement )
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler )
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.SetHandler(Context , IElement , IMauiContext )
   at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Activity , IWindow , IMauiContext )
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity , IApplication , Bundle )
   at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle )
   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0)
  --- End of managed Java.Lang.IllegalStateException stack trace ---

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.app/crc64d002a6d246c183e1.mm}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3644)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7918)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Caused by java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5248)
       at android.view.ViewGroup.addView(ViewGroup.java:5077)
       at android.view.ViewGroup.addView(ViewGroup.java:5017)
       at android.view.ViewGroup.addView(ViewGroup.java:4989)
       at crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_onCreate(MauiAppCompatActivity.java)
       at crc6488302ad6e9e4df1a.MauiAppCompatActivity.onCreate(MauiAppCompatActivity.java:48)
       at android.app.Activity.performCreate(Activity.java:8342)
       at android.app.Activity.performCreate(Activity.java:8321)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3625)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7918)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
@tranb3r tranb3r added the t/bug Something isn't working label Aug 2, 2023
@samhouts samhouts added platform/android 🤖 high It doesn't work at all, crashes or has a big impact. area-controls-toolbar ToolBar area/toolbar labels Aug 2, 2023
@rachelkang rachelkang added the s/needs-repro Attach a solution or code which reproduces the issue label Aug 2, 2023
@ghost
Copy link

ghost commented Aug 2, 2023

Hi @tranb3r. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@rachelkang rachelkang added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Aug 2, 2023
@ghost
Copy link

ghost commented Aug 2, 2023

Hi @tranb3r. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@tranb3r
Copy link
Author

tranb3r commented Aug 2, 2023

Here is a repro: https://github.com/tranb3r/Issues/tree/main/MauiAppDontKeepActivities

Steps to reproduce:

  • in android settings, developer options, enable "don't keep activites"
  • launch test app, then tap on home button: app goes to background, and is killed by system
  • launch app again, it crashes

This is happening when the MainPage sets the NavigationPage.TitleView.

This is a regression in net8.
Same behavior in net8-pre5 and net8-pre6.
No crash with net7.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Aug 2, 2023
@tranb3r tranb3r changed the title Java.Lang.IllegalStateException: The specified child already has a parent [net8] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) Aug 2, 2023
@samhouts samhouts added i/regression This issue described a confirmed regression on a currently supported version and removed s/needs-attention Issue has more information and needs another look labels Aug 2, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Aug 2, 2023
@samhouts samhouts changed the title [net8] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) [regression/8.0.0-preview.2.7871] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) Aug 2, 2023
@jsuarezruiz
Copy link
Contributor

Cannot reproduce the issue with preview 7 or in the current net8 development branch. Maybe I am missing something?
issue-16499

@jsuarezruiz jsuarezruiz added the s/needs-info Issue needs more info from the author label Aug 10, 2023
@ghost
Copy link

ghost commented Aug 10, 2023

Hi @tranb3r. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@tranb3r
Copy link
Author

tranb3r commented Aug 10, 2023

I've just tested my sample app with net8-pre7 and I can still reproduce the issue.
@jsuarezruiz Are you running my sample app?
In your screen capture, it seems like the app title and splashscreen are different. Maybe some other difference could explain the exception?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Aug 10, 2023
@samhouts samhouts added potential-regression This issue described a possible regression on a currently supported version., verification pending i/regression This issue described a confirmed regression on a currently supported version and removed i/regression This issue described a confirmed regression on a currently supported version potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 5, 2023
@samhouts samhouts changed the title [regression/8.0.0-preview.2.7871] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) [regression/8.0.0-preview.3.8149] Crash when using NavigationPage.TitleView (Java.Lang.IllegalStateException: The specified child already has a parent) Sep 7, 2023
@samhouts
Copy link
Member

samhouts commented Sep 7, 2023

Confirmed that this was a regression between 8.0.0-preview.2.7871...8.0.0-preview.3.8149.

Not sure which PR is the culprit. #13879 is the most sus to me.

@samhouts
Copy link
Member

samhouts commented Sep 7, 2023

Also, still repros in pre7.

@samhouts samhouts removed the s/needs-attention Issue has more information and needs another look label Sep 7, 2023
@tranb3r
Copy link
Author

tranb3r commented Sep 11, 2023

Any update? Thanks

@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Sep 13, 2023
@tranb3r
Copy link
Author

tranb3r commented Sep 14, 2023

Still happening in RC1.

@github-project-automation github-project-automation bot moved this from In Progress to Done in MAUI SDK Ongoing Sep 25, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Oct 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-toolbar ToolBar fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! high It doesn't work at all, crashes or has a big impact. i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants