0

我正在 Windows Phone 中开发一个应用程序。在我的应用程序中,有必要处理锁定按键事件,因为我使用了 Timer。这是我的代码

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

        PhoneApplicationService.Current.Activated += Micropphone_Current_Activated;
        PhoneApplicationService.Current.Deactivated += Micropphone_Current_Deactivated;
        if (_autowizardtimer != null)
        {
            _autowizardtimer.Stop();
            _autowizardtimer.Tick -= _timer_Tick;
            if (_endtimer != null)
            {
                _endtimer.Stop();
                _endtimer.Tick -= _endtimer_Tick;
            }
        }      
    }
    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
       if (_autowizardtimer != null)
        {
            PhoneApplicationService.Current.Activated -= Micropphone_Current_Activated;
            PhoneApplicationService.Current.Deactivated -= Micropphone_Current_Deactivated;
            _autowizardtimer.Stop();
            _autowizardtimer.Tick -= _timer_Tick;
        }
        if (_endtimer != null)
        {               
            _endtimer.Stop();
            _endtimer.Tick -= _endtimer_Tick;
        }
    }

基本上我想做的是,当用户按下锁定键时,计时器暂停,释放锁定键后,计时器开始计时。问题出在OnNavigatedFrom方法上。当我按下锁定键时,此方法不会调用。我没有得到什么问题。有人能说出为什么会这样吗?或者有没有其他方法来处理锁定按键?

4

2 回答 2

1

当屏幕被锁定时,您不需要停止计时器,因为您的应用程序将自动停用(除非您明确告诉系统您希望您的应用程序在锁定屏幕下运行)。

不过,如果您想检测屏幕锁定或解锁的时刻,您可以分别使用事件ObscuredUnobscured

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206951(v=vs.105).aspx#BKMK_Understandingtheeventsthatwhenthephoneislockedorunlocked

于 2013-08-21T11:35:52.050 回答
0

当您按下锁定键时,您基本上不会从页面导航,但您正在停用您的应用程序。在您的情况下,我也会在 App.xaml.cs 的激活和停用事件中处理此计时器。

请在此处查看 Windows Phone 应用程序生命周期:http: //msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008 (v=vs.105).aspx

问候,

于 2013-08-21T11:46:15.313 回答