我有這個問題吐司通知,我的應用程序顯示吐司通知只有當它被激活(即:當我使用它)。如果應用程序被激活,吐司通知只會彈出
這裏是我的Toast通知代碼:
private void ShowToastNotification(string text)
{
var xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
xml.GetElementsByTagName("text")[0].AppendChild(xml.CreateTextNode(text));
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(xml));
}
我的應用程序是一個簡單的提醒應用,用戶設定的時間和文本,當它是時間的應用程序將顯示該文本Toast通知。 我只是使用循環計時器,每5秒檢查一次提醒。
public MainPage()
{
this.InitializeComponent();
DispatcherTimer d = new DispatcherTimer();
d.Interval = new TimeSpan(0,0,5);
d.Start();
d.Tick += delegate
{
CHECK();
};
}
private void CHECK()
{
foreach (REMINDER_CLASS er in REMINDERS)
{
if (DateTime.Now.ToString("MM/dd/yyyy hh:mm:tt") == er.DateTime)
{
ShowToastNotification(er.Reminder);
break;
}
}
}
所以當時間到來時它不顯示的Toast通知,當我點擊應用程序它顯示了通知,它就像它已被暫停,當我打開它,它恢復。
順便說一句,我在我的appxmanifest中設置了Toast,並在我的聲明中添加了BackGround類型的任務:Timer和System Event。
該解決方案可能不允許應用程序休眠或暫停,但我不知道如何停止應用程序暫停。 另一種解決方案可能是BackGround Tasks,如果您爲後臺任務提供了一個很好的簡單資源,我將非常感激。
非常感謝,這確實是解決方案! – BOSS 2013-05-13 14:32:30