user3165999
user3165999

Reputation: 159

Refresh page while navigating to it on back button press

I am trying to build a xamarin forms app. I need refresh my page when user presses android device back button press. I tried to use OnAppearing method, but its not invoked when page is displayed on back button press. Is there any method that gets called when a page is displayed from modal stack? Or Why OnAppearing method only called on initial launch? Thanks.

Upvotes: 0

Views: 10293

Answers (2)

Ohraidig
Ohraidig

Reputation: 1

For me this works perfect:

public MainPage()
        {
            InitializeComponent();
        }

protected override void OnAppearing()
        {
            //Write the code of your page here
            base.OnAppearing();
        }

Upvotes: 0

Mario Galván
Mario Galván

Reputation: 4032

If you want to refresh your page I suggest MVVM architecture with bindings:

https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_binding_basics/

But this takes some time to learn, there are some other ways to do this for example:

1.- Sending the objects you want to refresh on the next views as parameters.

2.- Create static methods to refresh your UI.

3.- Doing Callbacks/Delegates or Commands in order to refresh your view:

https://blog.xamarin.com/simplifying-events-with-commanding/

Upvotes: 1

Related Questions