Push notification 如何在后台任务中保存原始通知,然后从主项目访问它

Push notification 如何在后台任务中保存原始通知,然后从主项目访问它,push-notification,windows-phone-8.1,Push Notification,Windows Phone 8.1,这件事我已经坚持很久了 我收到一个原始通知并生成一个toast: public异步无效运行(IBackgroundTaskInstance taskInstance) { var deleral=taskInstance.getDeleral(); BackgroundTaskDeleral _deleral=taskInstance.getDeleral(); RawNotification rn=taskInstance.TriggerDetails作为RawNotification; To

这件事我已经坚持很久了

我收到一个原始通知并生成一个toast:

public异步无效运行(IBackgroundTaskInstance taskInstance)
{
var deleral=taskInstance.getDeleral();
BackgroundTaskDeleral _deleral=taskInstance.getDeleral();
RawNotification rn=taskInstance.TriggerDetails作为RawNotification;
ToastTemplateType toastTemplate=ToastTemplateType.ToastText02;
var toastDescriptor=toasnotificationmanager.GetTemplateContent(toastTemplate);
var txtNodes=toastDescriptor.GetElementsByTagName(“文本”);
txtNodes[0].AppendChild(toastDescriptor.CreateTextNode(“原始”);
txtNodes[1].AppendChild(toastDescriptor.CreateTextNode(rn.Content));
var toast=新toast通知(toast描述符);
var toastNotifier=ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);
等待写入文件(rn);
延迟。完成();
}
然后我将原始通知写入一个文件:

private异步任务writeToFile(rawn)
{
var file=wait ApplicationData.Current.LocalFolder.CreateFileAsync(
文件名,CreationCollisionOption.OpenIfExists);
使用(var netStream=await file.OpenStreamForWriteAsync())
{
使用(var writer=newstreamwriter(netStream,Encoding.UTF8,512,true))
{
WriteLine(rn.Content.ToString());
}
}
}
静态只读字符串FILENAME=“background.txt”;
}
对于单个通知,它可以正常工作,但是如果我尝试创建一个包含所有通知的列表,并将其发送到listView的主项目,它就不能正常工作

公共静态IAsyncOperation ReadLastRunTimeAsync()
{
返回(ReadFromFileAsync().AsAsAsyncOperation());
}
静态异步任务ReadFromFileAsync()
{
string runtime=“Not Run”;
IEnumerable集合=null;
//ObservableCollection列表=新的ObservableCollection();
尝试
{
var file=wait ApplicationData.Current.LocalFolder.GetFileAsync(文件名);
使用(var netStream=await file.OpenStreamForReadAsync())
{
使用(var reader=newstreamreader(netStream))
{
//运行时=reader.ReadToEnd();
弦线;
而((line=reader.ReadLine())!=null)
{
collection.Concat(new[]{line});//添加到列表。
//reader.WriteLine(行);//写入控制台。
}
}
}
}
捕获(FileNotFoundException)
{
}
return(collection.ToList());
}
请帮忙。 如果有其他方法,请指导我。 我只需要一个所有收到通知的列表视图