Search code examples
c#windows-store-apps

get a callback method when I tap on my app again - Windows Store app


I did the following: 1.launched my app 2.launched another app 3.tap on my app again (for instance taking it from the app list)

At step .3 I would expect to get a message callback, but I dont.

In the file App.xaml.cs, I added the method onResuming this

way:

public App()
{
        //this.askToBeOnLockScreen();
        this.createRegisterBgTask();

        this.InitializeComponent();

        this.Suspending += OnSuspending;
        this.Resuming += OnResuming;
    }

here I override the 2 methods:

    private void OnResuming(object sender, object e)
    {
        Debug.WriteLine("OnResuming ...................");
    }





    private void OnSuspending(object sender, SuspendingEventArgs e)
    {
        Debug.WriteLine("onsuspending ......................................................");
        var deferral = e.SuspendingOperation.GetDeferral();

        deferral.Complete();
    }

not even the onsuspending is called.

What am I doing wrong?

I am new to Windows store app


Solution

  • You are probably starting the app from Visual Studio and to trigger suspend/resume you are simply using the minimizing button from your app. This doesn't work for apps which are started from VS and have a debugger connected.

    To simulate supend/resume use the lifecyle-events toolbar in Visual Studio. It looks like this:enter image description here

    Don't worry if you don't find it, it will appear right after you started debugging your app in Viusal Studio.