Xamarin.iOS – Let Your ViewController Know the App is Coming to Foreground

Quick tip to share.  Found it on the developers lifeline (aka Stackoverflow).

If you ever wanted to alert your Viewcontrolller that your app is back in the foreground (from being in the background), simple add an Observer.   Just create your custom method to handle the “notification” and whenever your app is brought to the foreground, NSNotificationCenter will post a DIdBecomeActiveNotification to your Viewcontroller.


//class level var
NSObject _contentObs
public override void ViewWillAppear (bool animated){    
   //Don't forget to Dispose this
    _contentObs = NSNotificationCenter.DefaultCenter.AddObserver(
                     notification => OnBecameActive ());
    base.ViewWillAppear (animated);

void  OnBecameActive ()
         //Your Code    

Leave a Reply

Your email address will not be published. Required fields are marked *