Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page lifecycle events in xamarin.forms

I just developed my first xamarin.forms app. I am excited about xamarin.forms, but I miss several events.

Are there any page-lifecycle-events in a xamarin.forms ContentPage?

I know of these two:

protected override void OnAppearing() { }  protected override void OnDisappearing() { } 

But the OnAppearing() event only fires once. On Android, when I push the start button and go back to my app, this event does not fire again.

Is there a workaround for this (like OnNavigatedTo in WindowsPhone-pages)?

Thanks.

like image 680
Joehl Avatar asked Mar 25 '15 09:03

Joehl


People also ask

What are the life cycle of xamarin forms app development?

The application lifecycle can be summarized in four events: startup, suspension, resume, and shutdown. The Android, iOS, and Windows platforms manage these events differently, but Xamarin.

Which modal navigation events raised after a page has been popped Modally?

Modal navigation events ModalPushed - raised after a page has been pushed modally. ModalPopping - raised when a page is modally popped. ModalPopped - raised after a page has been popped modally.

What is content page in xamarin?

A content page is a simple blank page which allows making a single “View” object, which further consists of different layouts like GridLayout and RelativeLayout. The picture below shows a Content Page that includes some text. XAML Code. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

Is xamarin still supported?

NET. Xamarin support will end on May 1, 2024 for all Xamarin SDKs. Android 13 and Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin will target.


Video Answer


1 Answers

So the OnAppearing event is fired when your page is appearing. I.e. you have navigated to that page or back to that page from another in the Stack. There is currently no Page Lifecycle events as you can see from the API documentation

I think what you are talking about is if you put your application to sleep and navigate back into it the OnAppearing event is not fired, This is because your page hasn't appeared because it was already there, the application was just asleep.

What you are looking for is the App Lifecycle which includes methods such as:

protected override void OnStart() {     Debug.WriteLine ("OnStart"); } protected override void OnSleep() {     Debug.WriteLine ("OnSleep"); } protected override void OnResume() {     Debug.WriteLine ("OnResume"); } 

You can then use the OnResume event to do what you are looking for.

That Xamarin Document includes the changes that must be made to old Xamarin projects to access these events. e.g. your App class in your shared library must inherit from Xamarin.Forms.Application and changes must also be made to the AppDelegate and MainActivity.

like image 200
User1 Avatar answered Sep 19 '22 04:09

User1