Search code examples
windows-phone-7push-notificationmpnsbackground-agents

Building long-life background agent (more than 2 weeks) in WP7


I need long-term working background agent in wp7. I know that default and maximum life-cycle for such agents is 2 weeks. Also i got situation, when battery is critical low, all background agents are turning off.

So now i see only two workaround for this situation:

  • i can restart background agent every time when my application is launched (but i have no warranty, that user will launch this application at least every 2 weeks)
  • or i can use push notifications to turn on background agent.

Am i right? Are there any other workarounds?


Solution

  • You won't be able to use a push notification to turn on your background agent. If your app is not running at the time your notification comes through, your only options are to display Toast or change the Start Menu tile.

    Your first thought around restarting your background agent is what you will need to do to refresh. One thing you might want to consider is, in your background agent, keeping track of the last time it was refreshed by someone opening the app. Then, if you're getting close to the end of that lifecycle, you can change your tile image or text to reflect that the user needs to refresh. I've seen a couple apps that do this.

    You have to keep in mind that your background agent is not guaranteed to be active. It can be shut down by low battery or user request without ever telling you, or your app.