How to receive a notification in MonoTouch that my application is closed / sent to the background?

Although I think this is a pretty trivial question, I could not find the answers.

My question is:

Is there a way to get a notification in the MonoTouch iPhone app when my app closes or goes to the background (by the user by pressing the home button)?

I thought redefinition WillTerminatewas good for this, but in the debugger it is never called.

+5
source share
1 answer

There are two ways to get notified when an application goes into the background:

and. Override the appropriate method in AppDelegate:

public override void DidEnterBackground(UIApplication application)
{
    // App entered background, do some light stuff here, 
    // there is not much time before getting suspended
}

. NSNotificationCenter:

 NSObject observer = NSNotificationCenter.DefaultCenter.AddObserver(
    UIApplication.DidEnterBackgroundNotification, 
    delegate(NSNotification ntf) {

            // Same as above
    });

NSObject, AddObserver, , :

NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
+8

All Articles