简体   繁体   中英

What is the life cycle of a ContentPage in Xamarin Forms iOS and why does it crash when I switch to another app?

My Xamarin iOS app is crashing on a ContentPage when I switch away from it to another app.

The first occurrence was in a label renderer, so I wrapped it in a try catch block:

protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
    //Add a try because of this:    
    //https://stackoverflow.com/questions/46881393/ios-crash-report-unexpected-start-state-exception
    try
    {
        base.OnElementChanged(e);

        if (label != null)
        {
            sv = label.Parent as ScrollViewEx;
        }
    }
    catch
    {

    }

}

Now it is crashing in another part of the app trying to access a disposed editor object when I switch away.

Is there a life cycle thing going on here that I need to be aware of in terms of why the OS is trying to re-render UI objects in such circumstances?

And how can I generically protect my app from these sorts of crashes without having to wrap every single UI object in a try catch just because I'm switching to another app?

I am not familiar with the issue, however, what I can recommend is at the end of the catch keyword, put (Exception e) as a parameter

try
{...}
catch(Exception e)
{
    Debug.WriteLine(e.Message);
}

This way you will be one step closer to figuring out this painful bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM