1
votes

So, this is the problem that I'm trying to solve using background agents: I need to continue on logging the user location when he goes offline in background even after device reset (thing of a running app for context).

To try and solve this I've used a Periodic task from this approach word-for-word, which did work in debug mode. But, as I left the phone unattended overnight I've had only one log for the user after half an hour of leaving the phone. No further entries have been recorded (have in mind that I've used test log entry and not real GPS signal, which means I only triggered simple log writing for test purposes).

Am I missing something? Is this not a valid solution for this problem. If so, could you please provide a reason for this, as I was unable to find any documentation that speaks of that sort of limitation.

1
Can you share the code from the background agent please?kernanb
The code is exactly as in the link example, that is why I have not pasted it here.Milos Maksimovic

1 Answers

1
votes

The OS on WP 8.1 has some very strict rules about when the background agent will run and for how long. Once every 30 minutes is consistent with the MSDN documentation here and with my observations. If your code is correctly written you should see one entry approximately each 30 minutes. If you were to write a store application for a tablet you'd have more options. There, the OS behavior vis-à-vis of background agents is a little bit more lax (some of this is not very well documented). Since you are targeting Win Phone I am not going to go into details regarding background agents on a tablet.

I am not sure if it would work for your use case but one thing that comes to mind is to have the user keep the app running. You can prevent the phone from going into a low power state and suspend your app (like a navigation app does). To do that see PhoneApplicationService.UserIdleDetectionMode. If you do that then make sure you make the screen black (or mostly black) and use sleeps (await Task.Delay(...)) appropriately in order to conserve the battery.