You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI应用返回首页触发Android ANR及ObjectDisposedException问题求助

MAUI应用返回首页时出现ANR及ObjectDisposedException问题

我的MAUI应用在Google Play Console中被报告了4起ANR故障,涉及设备包括Google Pixel 5、小米Redmi 6A、Generic Small Desktop (x86)以及Google Pixel 2。从附带的错误视频来看,所有问题都发生在返回首页操作时,但不是首次返回,且返回前所在的页面和执行的操作没有固定规律。

我使用以下代码实现返回首页:

(App.Current as App).MainPage = new AppShell(); 
await Shell.Current.GoToAsync($".", false);

从Google Play Console提供的堆栈跟踪中找不到任何与应用业务控件相关的信息,因此推测这是MAUI框架层面的问题,而非业务代码导致。我在GitHub上见过类似的堆栈跟踪,但没找到可行的解决方案。

目前已尝试更新所有NuGet包,但问题仍然存在。另外我还测试了注释掉切换语言时用到的代码(App.Current as App).MainPage = new AppShell();,之后报告里仍有2起错误,不确定这样是否有改善。

以下是完整的堆栈跟踪信息:

Exception android.runtime.JavaProxyThrowable: System.ObjectDisposedException: 对象已释放(通用异常)
已释放对象名称:Microsoft.Maui.Platform.MauiMaterialButton
at Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable )
at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String , IJavaPeerable , JniArgumentValue* )
at Android.Views.View.SetOnClickListener(IOnClickListener )
at Microsoft.Maui.Handlers.ButtonHandler.DisconnectHandler(MaterialButton )
at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IButton, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Google.Android.Material.Button.MaterialButton, Xamarin.Google.Android.Material, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnDisconnectHandler(View ) at Microsoft.Maui.Handlers.ViewHandler.OnDisconnectHandler(Object ) at Microsoft.Maui.Handlers.ElementHandler.DisconnectHandler(Object ) at Microsoft.Maui.Handlers.ElementHandler.Microsoft.Maui.IElementHandler.DisconnectHandler() at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler ) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler ) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement , IMauiContext ) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement , IMauiContext ) at Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.UpdateContent() at Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.<>c.<.cctor>b__67_6(FrameRenderer , Frame ) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0[[Microsoft.Maui.Controls.Frame, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0(IElementHandler , IElement )
at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String , IElementHandler , IElement )
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler , IElement )
at Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer1[[Microsoft.Maui.Controls.Frame, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement , IPlatformViewHandler , Action1 , Frame& , IPropertyMapper& , IPropertyMapper , Boolean )
at Microsoft.Maui.Controls.Handlers.Compatibility.ViewHandlerDelegator1[[Microsoft.Maui.Controls.Frame, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement , Action1 , Boolean )
at Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.Microsoft.Maui.IElementHandler.SetVirtualView(IElement )
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler )
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler )
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement , IMauiContext )
at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement , IMauiContext )
at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView )
at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement ) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler ) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler ) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement , IMauiContext ) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement , IMauiContext ) at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler ) at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler , IContentView ) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0(IElementHandler , IElement )
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.Handlers.ViewHandler.SetVirtualView(IElement )
at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView ) at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView ) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement )
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler )
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler )
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement , IMauiContext )
at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView , IMauiContext )
at Microsoft.Maui.Controls.Platform.Compatibility.ShellFragmentContainer.OnCreateView(LayoutInflater , ViewGroup , Bundle )
at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr , IntPtr , IntPtr , IntPtr , IntPtr )
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L , IntPtr , IntPtr , IntPtr , IntPtr , IntPtr )
at crc640ec207abc449b2ca.ShellFragmentContainer.n_onCreateView
at crc640ec207abc449b2ca.ShellFragmentContainer.onCreateView (ShellFragmentContainer.java:41)
at androidx.fragment.app.Fragment.performCreateView (Fragment.java:3104)
at androidx.fragment.app.FragmentStateManager.createView (FragmentStateManager.java:524)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState (FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether (FragmentManager.java:1899)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute (FragmentManager.java:1817)
at androidx.fragment.app.FragmentManager.execSingleAction (FragmentManager.java:1729)
at androidx.fragment.app.BackStackRecord.commitNow (BackStackRecord.java:317)
at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder (FragmentStateAdapter.java:341)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow (FragmentStateAdapter.java:276)
at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow (FragmentStateAdapter.java:67)
at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached (RecyclerView.java:7867)
at androidx.recyclerview.widget.RecyclerView$5.addView (RecyclerView.java:893)
at androidx.recyclerview.widget.ChildHelper.addView (ChildHelper.java:107)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt (RecyclerView.java:8902)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView (RecyclerView.java:8860)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView (RecyclerView.java:8848)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1645)
at androidx.recyclerview.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1591)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:668)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:4309)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout (RecyclerView.java:4012)
at androidx.recyclerview.widget.RecyclerView.onLayout (RecyclerView.java:4578)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at androidx.viewpager2.widget.ViewPager2.onLayout (ViewPager2.java:527)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild (HeaderScrollingViewBehavior.java:149)
at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:43)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild (AppBarLayout.java:2253)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout (CoordinatorLayout.java:953)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1582)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at androidx.drawerlayout.widget.DrawerLayout.onLayout (DrawerLayout.java:1263)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829)
at android.widget.LinearLayout.layoutHorizontal (LinearLayout.java:1818)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1584)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1582)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout (DecorView.java:784)
at android.view.View.layout (View.java:22844)
at android.view.ViewGroup.layout (ViewGroup.java:6389)
at android.view.ViewRootImpl.performLayout (ViewRootImpl.java:3475)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2943)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1948)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8177)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:972)
at android.view.Choreographer.doCallbacks (Choreographer.java:796)
at android.view.Choreographer.doFrame (Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:957)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:223)
at android.app.ActivityThread.main (ActivityThread.java:7664)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)


内容的提问来源于stack exchange,提问作者Silny ToJa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 02:29:53