0

我有一个在收到原始通知时运行的后台任务。

如果应用程序不在前台,我想显示 toast 通知,但如果它前台,我不想显示通知。

是否可以测试应用程序是否在前台BackgroundTask?如果是这样,怎么做?

4

1 回答 1

0

You need to store some variable in IsolatedStorage and change it's value to true when the app is in the foreground. After, when your apps go to background you need to change that variable value to false.

In your background task you need to check the value of this variable in isolated storege. And of course you need to protect your code (one way is to use mutex) to prevent access errors.

This is the simpliest and recommended way to communicate between App and BackgroundTask. No 'from the box' mechanism is provided for such communication so you have to implement your own.

于 2014-09-17T13:01:42.000 回答