Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch: Controller brought to foreground - Notification?

MonoTouch

When an app is brought back to the foreground, I need the ViewController that becomes active to know about this.

Is there an event or override I can use to determine that the view was brought to the foreground.

I did find "WillEnterForegroundNotification" but it's a String, so am not sure how it's used.

like image 915
Ian Vink Avatar asked Feb 24 '23 16:02

Ian Vink


1 Answers

I found this:

Put this in the CTOR of the ViewController:

NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification, 
    EnterForeground); 

Create then this method to handle the event in the view controller.

void EnterForeground (NSNotification notification)
{
    Console.WriteLine("EnterForeground: " + notification.Name); 
}

Note: When your app is brought to the foreground, the UIApplicationDelegate will get this raised first, a good place to clear things like login details and security related checks.

public override void WillEnterForeground (UIApplication application)
like image 79
Ian Vink Avatar answered Apr 08 '23 15:04

Ian Vink