Forum Xamarin Xamarin.Forms

How to avoid PushModalAsync from retrieving variable values from earlier calls?

Hello there, in my Xamarin forms application I have a button that opens another ContentPage by calling “Navigation.PushModalAsync(new Class());” said class contains public variables with default values that get modified during the usage of the application. My issue is whenever the back button is pressed on Android, and the button is re-pressed, instead of the contentpage showing up with its default values, it shows up with the old values from last time it was open, despite me creating a new instance of the class every time PushModalAsync is called. I’ve tried a lot of different things but nothing seems to work.
Tagged:

Best Answer

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    Are these public variables static ones?
    If so, they won't return to the original status after being modified somewhere else in your application.
    You could try to define a normal public property in that presentation page class.
    It will be refreshed if you display the class with a new instance each time.

Answers

  • AzizAziz Member ✭✭

    Maybe you can try re-setting the contentpage variables in the "OnAppearing()" function instead of the constructor.

  • > @Aziz said:
    > Maybe you can try re-setting the contentpage variables in the "OnAppearing()" function instead of the constructor.

    I did think of this, but I was hoping for a cleaner way to do it since my project has over 100 lines of global variables and it’d look really ugly that way.
  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    Are these public variables static ones?
    If so, they won't return to the original status after being modified somewhere else in your application.
    You could try to define a normal public property in that presentation page class.
    It will be refreshed if you display the class with a new instance each time.

Sign In or Register to comment.