Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Detecting application states


In this recipe, we will discuss how to detect the state of the application and respond accordingly when an application is transited from the active to the inactive state and vice versa.

Getting ready

Create a new Single View Application in Xamarin Studio and name it AppStateApp.

How to do it...

Perform the following steps:

  1. Add the following method override to the AppDelegate class:

    public override void OnActivated (UIApplication application)
    {
      Console.WriteLine("Activated, application state: {0}", application.ApplicationState);	
    }
    public override void OnResignActivation (UIApplication application)
    {
      Console.WriteLine("Resign activation, application state: {0}", application.ApplicationState);
    }
    public override void DidEnterBackground (UIApplication application)
    {
      Console.WriteLine("Entered background, application state: {0}", application.ApplicationState);
    }
    public override void WillEnterForeground (UIApplication application)
    {
      Console.WriteLine("Will enter...