1

I just read that while Windows Phone 7.5 background tasks can poll for a location, they don't actually poll real-time from the GPS but rather the location API calls return a system-cached position that's only updated once every fifteen minutes.

That limitation of course completely invalidates any attempt at having navigation run in the background as you can get pretty damn far off-track in fifteen minutes, let alone that a background task can only run once every thirty minutes or so!

That said, Nokia's navigation app and reportedly Runtastic's app do continue tracking when in the background (i.e. not just under the lock screen) and both are in the marketplace meaning they have been approved, so does anyone know how they managed to do what the SDK supposedly doesn't support?

For reference, we don't actually need real-time tracking... maybe once a minuted or so, and we don't need that much accuracy... maybe 100 feet or so... but we do need more than we have been given. We just don't know how they're doing it in approved apps.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
  • possible duplicate of [How can i run my GPS application in background?](http://stackoverflow.com/questions/6952413/how-can-i-run-my-gps-application-in-background) – Ritch Melton Apr 20 '12 at 00:42
  • Yes, it sucks, but its well documented. Maby WP8 will have a solution. – Ritch Melton Apr 20 '12 at 00:43
  • Run your app under screen lock and turn off IdleDetection. – Derek Beattie Apr 20 '12 at 02:41
  • Derek... that's crazy as that would kill the battery. Besides, that also requires our app to be in the foreground which sort of defeats the purpose of background tasks in the first place. And @Rich, yes, it's documented, but Nokia has a nav app that does exactly this and they aren't first-party (ala like wide Live Tiles). If MS gave them exclusive access to that, that would really, really suck, especially since both Nokia and Microsoft are bitching that they need more apps, then hobble our ability to create them. Just crazy. (Plus, Nokia's GPS app stinks.) – Mark A. Donohoe Apr 20 '12 at 07:35
  • True, that's how a lot of the gps apps do it right now though. – Derek Beattie Apr 22 '12 at 21:30
  • Yeah. Really, really disappointed in what Microsoft left out here. This is the only 'smart' platform that doesn't allow something as simple as background location tracking. Between that and the live-tiles only being able to be updated once every 30 minutes (because of the same limitations) I think this platform is all but dead to our company. We'll stick with iOS and Android. (Heck, even the Pre with its webOS could do this! Just crazy!) – Mark A. Donohoe Apr 22 '12 at 22:32

2 Answers2

5

You'll only be able to retrieve the location when your PeriodicTask executes (Approximately every ~30 minutes, depending on OS scheduling). The location data it fetches from GeoCoordinateWatcher will be from the OS's cache rather than directly from the GPS hardware. If nothing is running the OS will update this with coarse-grained data approximately every 15 minutes. However if an application has executed and retrieved fine-grained GPS hardware data than this will be the data you'll retrieve in your PeriodicTask. You can see examples of this by accessing the GPS in your foreground app and force-scheduling your PeriodicTask with ScheduledActionService.LaunchForTest.

MrMDavidson
  • 2,705
  • 21
  • 20
  • 2
    That's basically what I led with. You just added the bit about another app updating the cache, but that's besides the point as *my* background task still only accesses cached data. And actually you can use the heavy background task which can run as frequently as once every ten minutes. But again, that still doesn't answer the question if it can be done or not. It of course can as Nokia has a nav app and they aren't first-party (ala wide live tiles) but then again, maybe they have exclusive access the rest of us don't thanks to their MS partnership which would be a pity. – Mark A. Donohoe Apr 20 '12 at 07:30
  • 2
    I presume by "heavy background task" you mean `ResourceIntensiveTask`? If so I'm not seeing anywhere that they can run every 10 minutes but instead that they can run for **up to** 10 minutes. However given the other restrictions placed on them (Must have power, WiFi, > 90% battery, screen lock. Ref: http://msdn.microsoft.com/en-us/library/hh202942(v=vs.92).aspx) I doubt it's useful to you. Long story short: What you're directly asking does not seem possible with the standard SDK. You might need to look into interop (Ref: http://forum.xda-developers.com/showthread.php?t=1299134) but... – MrMDavidson Apr 21 '12 at 00:42
  • 1
    Using interop requires a device to be interop unlocked. There is rumour that some market place ingested applications are being found with native and interop code (Ref: http://pocketnow.com/windows-phone/microsoft-starts-allowing-native-arm-code-in-wp7-apps) but as to if your application would be allowed into the market place with such code? You're taking a gamble. It sounds like something that might require technical exemption when being certified. Details on certification / exemption: http://msdn.microsoft.com/en-us/library/hh202928(v=vs.92).aspx – MrMDavidson Apr 21 '12 at 00:47
  • 1
    Aaaah! @Mrm, you're right! I read that wrong. 'Up to', not 'every'. (And yes, got the name wrong.) I really don't know how the hell MS can call them 'Live Tiles' if they only update once every 30 minutes, and while yes, you can update them as much as you want while you're in your app, that defeats the purpose as you already have a full damn screen to use at that point so you don't need the tiles! I mean forget GPS... we can't even write a simple clock face! I'm very, *very* disappointed in MS and this completely ridiculous limitation. Seriously considering returning that new Lumia 900. – Mark A. Donohoe Apr 21 '12 at 05:37
  • 1
    What is it you're trying to achieve? If it's an application that tracks fine grained position data (Eg. Endomondo) or gives directions (Eg. Bing Maps) then turning off `IdleDetection` as per Derek's suggestion is the way to go. An `Obscured` event gets raised when the lock screen comes on and the UI stops redrawing. You can use this event to do as little as possible (ie. Just GPS tracking) to extend the battery life. More info here: http://msdn.microsoft.com/en-us/library/ff941090(v=vs.92).aspx If this is an app for your own use check out xda-developers for interop / non-standard stuff. – MrMDavidson Apr 21 '12 at 06:33
  • 1
    again, I need a *background* task--something that can run when you're using another app or when the phone is sleeping. Think the location-based Reminders app on iOS where you can set a reminder to pop up when you leave work or arrive at home. If I went with your or Derek's Obscured approach, the minute you switched to another app, it would stop! And we only need 100 ft or so. But it does have to update at least once a minute at a minimum. They should have just added background location permissions and let the user decide what to spend their battery on. This is ridiculous. So dumb! – Mark A. Donohoe Apr 21 '12 at 21:06
  • 1
    And again: what you're asking for is not possible with the current (7.1.1) SDK. See the similar question: http://stackoverflow.com/questions/9060429/how-to-send-gps-data-to-server-every-5-minutes or from Ritch's original comment. – MrMDavidson Apr 21 '12 at 23:23
  • 2
    And again, yes it is! See Nokia's GPS app! It does it. Apparently so does an app called Runtastic (whereas Runkeeper doesn't.) The question is how. And if MS doesn't make that available to us, then again, how can they complain there's not enough support for their platform. – Mark A. Donohoe Apr 22 '12 at 04:55
  • 1
    Runtastic (and runkeeper and Endomondo) all make use of `IdleDetection`. If you install Runtastic you'll note that it asks if you'll "Allow runtastic to run even if your phone is locked?". Previously you'd actually see "run under lock screen" along with "location services", etc in the marketplace, but it's been removed. Nokia, and the other OEMs, have access to interop APIs which, without special permissions, you do not. Your only option, as a run-of-the-mill third party developer, is to use `IdleDetection`. Is it perfect? No. Is it the only option available to you? Yes. – MrMDavidson Apr 22 '12 at 07:43
  • 1
    Please look again before posting information stating what apps do or dont do. Runkeeper does not support the feature I am referring to while Runtastic does. Runkeeper will pause if you switch away. Runtastic does not. Switching away is not idle-detection. I am not saying it doesn't support idle detection. I am saying that's not what I am referring to. – Mark A. Donohoe Apr 22 '12 at 17:05
  • 1
    Here's a customer reporting the same thing... Runtastic keeps working after a call comes in (app switches away) while Runkeeper does not. http://support.runkeeper.com/discussions/runkeeper-mobile-apps/685-windows-phone-7-app-pausing – Mark A. Donohoe Apr 22 '12 at 17:12
  • Tweet @justinangel and ask him, maybe he can tell you what the Nokia app is doing. – Derek Beattie Apr 22 '12 at 21:40
  • I just gave Runtastic a shot: started my morning commute then switched to Endomondo for the rest of it and switched back to Runtastic once I arrived. Runtastic continues to record **time** (Easy, store the time at deactviation, compare to the time on reactivation) but not the locations. Runtastic recorded my commute as 0.18km / 27mins. Endomondo as 6.56km / 23mins. I believe what the customer is saying is that Runtastic doesn't require any action when it resumes. But if you try it you'll see it **isn't** recording your location while not active. – MrMDavidson Apr 22 '12 at 22:58
  • What you could possibly do is store the current location on deactivation and then interpolate on reactivation of your application but that's only going to work for short / slow moving period of time. – MrMDavidson Apr 22 '12 at 22:59
  • @MrM, voting this as the answer since I don't like leaving questions open for too long (bad SO citizenship) and I'm not getting anywhere as to how Nokia did it. (I saw your answer regarding Runtastic. Makes sense.) I'm in the process of trying to decompile Nokia's app using Reflector and other such tools to see if they're using restricted APIs, but even if that's the case, it would be an unofficial answer, so again, this is the 'supported' one. – Mark A. Donohoe Apr 24 '12 at 16:50
  • No worries, @MarqueIV, sorry I couldn't give you a more acceptable answer. – MrMDavidson Apr 25 '12 at 12:26
  • I blame Microsoft's poor choice for a SDK. Huge fan of XAML, WPF, Silverlight and C#, but first, there was no native C++ support so performance was out the window, then their 'Live' tiles are more like 'clinically alive, but braindead' since you can't interact with them (even flipping them is 'random') and they can only update once every 30 minutes because of horrible background support. Add in no write-access to the contacts or calendar, and no way to integrate with caller ID or messaging, and it all but makes it useless for us. – Mark A. Donohoe Apr 25 '12 at 18:28
  • 1
    We were porting over ten apps (one was #1 in its iTunes category and reached #31 of highest grossing apps across *all* categories), but thanks to those limitations, nine of them can't be moved over. And now the rumors are even the latest-gen Nokia 900, their flagship won't be updateable to Apollo (perhaps because they realize they need a better SDK but their *enforced hardware limitations* of WP 7.x won't support it, but I'm guessing) and I can see why this platform isn't taking off. It's not the consumers. It's a beautiful and original OS. But if the developers can't write apps, it's dead! – Mark A. Donohoe Apr 25 '12 at 18:34
  • These comments are priceless, thank you for all the info and the research! – Alec Mev Aug 24 '12 at 08:44
0

Based on my experience with background tasks, you will not be able to achieve what you want with either Periodic or ResourceIntensive background tasks.

Despite documentation claiming that they run every 30 minutes, my experience is that they run sporadically and unpredictably. Over the last 14 hours, my app's periodic task has run a total of 6 times, and this is pretty consistent every day - it runs about once every two hours. For resource intensive tasks, I find they usually run about twice a night. I guess the OS has to balance all the processes on the phone and all the other apps clamoring to run their background tasks, so sometimes yours doesn't make the cut. Obviously, your mileage may vary based on your phone (lumia 800 in my case) and the apps you have installed.

If you want to write an app that tracks your location once a minute, my advice would be to enable it to run under the lock screen by disabling idle detection and make sure it has a low memory footprint to conserve battery life.

Ben Pink
  • 36
  • 6