Question

In Windows Phone 8, when I press start button, I should get Application_Deactivated and Application_Closing events. But when I set break point in these events, breakpoint doesn't hit. Why Application_Closing and Application_Deactivated are not getting called?

Please refer

Occurs when an application stops being the foreground application.

App.xaml

<Application
    x:Class="ContineousLocationTracking.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:ContineousLocationTracking" x:Key="LocalizedStrings"/>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"
            RunningInBackground="PhoneApplicationService_RunningInBackground" 
            />
    </Application.ApplicationLifetimeObjects>

</Application>
Was it helpful?

Solution

This what you put into Deactivation enent should be called. I would suggest to read Application lifecycle at MSDN. There are a lot of information, so I won't post it here.

You can surely set breakpoint at Deactivation event (according the disscusion in comments).

But Closing event is not called when you hit Start buton.

More usefull links:


If you are having problems check you App.xaml if those events are used:

<Application.ApplicationLifetimeObjects>
    <!--Required object that handles lifetime events for the application-->
    <shell:PhoneApplicationService
        Launching="Application_Launching" Closing="Application_Closing"
        Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>

And it wouldn't get called (instantly) if your App is set to run in Background (Location tracking). It can get called in specific circumstances.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top