-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Crash when switching MainPage from MDP to Page in Init/Appearing/ctor #2338
Comments
@PureWeen I'm currently dealing with an issue that may be resolved by your changes, but I can't tell from the code: I have an Android app that remains running in the background after the user closes the activity. I go through the full Xamarin.Forms.Forms.Init() every time the user re-opens the app since it creates a new activity. I'm currently cleaning up Xamarin.Forms by calling Application.ClearCurrent(), but I think it's leaving some of the old renderers around, in particular I think it's reusing the MasterDetailPageRender from the previous instance because it's never calling OnAttachedToWindow() when I re-open the app. So, I've got two questions:
|
The change will be apart of the next service release for 3.1
This kind of depends on your scenario. I've never used ClearCurrent in my applications. That's already called by base.OnCreate I currently just keep a static reference to my pages and then in OnCreate I look to see if that exists. If it does then I use that for setting main page other wise I recreate.
Marked For Dispose is just a way to indicate that it will be disposed eventually so just don't do anything more with this. That dispose essentially happens here
The actual dispose gets queue'd on the UI thread because if we just do everything immediately you run into Fragment issues when swapping out the main page in weird ways.
If you could put together a repro that would be helpful so I can see how you're handling things and how this isn't being called. I did a basic test with the Xamarin.Forms.ControlGallery.Android and detachwindow is called there when I background/resume an app |
@PureWeen Thanks for the update! I tracked down my issue: I have a PlatformEffect attached to my NavigationPage, which is the Detail of my MasterDetailPage. I'm using the new UpdateMenuItemIcon() of the NavigationPageRenderer to modify the ToolbarItems according to the effect. When the effect is first attached, the NavigationPage's renderer doesn't exist yet, so I was listening to the Appearing event to know when the renderer had been created. However, the startup Appearing event had actually been triggered already, and it was just a lucky side-effect that I was manually calling SendAppearing() later in my code for a different feature and that the renderer existed at that point. I wasn't calling SendAppearing() on the second run, so it looked like I was never getting the Appearing event. I changed my effect to instead listen for a property changed event on "Renderer", based on the attached property here, and everything's working as intended.
|
Description
When the MasterDetailContainer Dispose runs, it crashes if you're switching the MainPage immediately on a page load.
Steps to Reproduce
https://github.com/Schinwinkwinsky/DroidFragmentCrash
Expected Behavior
Test loads
Actual Behavior
Test immediately crashes
Basic Information
The text was updated successfully, but these errors were encountered: