What should I do in my lifecycle events?

WafflesWaffles ✭✭USMember ✭✭
edited January 2017 in Xamarin.Forms

So what should I be putting in OnResume, OnAppearing, OnDisappearing? A lot of people say "clean up" but Im not sure what that means. Ive seen other people say I should be unsubbing from events? I want to fool proof my pages and have ideal mem management. What are you guys using these events for? Are they safe to be used versus the native ones, because Ive also heard they can fire at weird and different times on the different platforms.

Best Answer

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ US ✭✭✭✭✭
    Accepted Answer

    @waffles

    Saving state for one. If your app is being backgrounded there is a good chance the user is going to kill it. Save dirty documents. Save navigation state so you can return to the same point when re-launched. On restore check things that might have changed: Location if that matters to your app... If you're editing a photo has the user deleted it behind your back

    What you put there is not universal. If it were it would have probably been part of the solution template. It's up to your app and what it does to determine what it needs to do.

Answers

  • Jesse_JiangJesse_Jiang ✭✭✭ USMember ✭✭✭

    If you App doesn't crash when go to background or come from background, it means that you did well on memory management.

    The .Net platform help you to do lots of memory management, you should not worried about that.

    Some Tips:
    Using Action/Func instead of Event.
    Remember to Unsubscribe when you using MessagingCenter

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭
    Accepted Answer

    @waffles

    Saving state for one. If your app is being backgrounded there is a good chance the user is going to kill it. Save dirty documents. Save navigation state so you can return to the same point when re-launched. On restore check things that might have changed: Location if that matters to your app... If you're editing a photo has the user deleted it behind your back

    What you put there is not universal. If it were it would have probably been part of the solution template. It's up to your app and what it does to determine what it needs to do.

Sign In or Register to comment.