Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

GPS, HTTP POST not running while phone is locked

I am developing an app that is designed to post the user's current location to a web service at some given interval. I am currently testing with an Android device. Things work fine when the app is up on the screen, and the device is awake. However, when I lock the screen, it stops posting. If I bring up the lock screen, but not unlock it, it will post, but then stops again after the screen goes dark.

The phone must be allowed to be locked for this app to be useful, so keeping it awake is not an option. I am currently trying several things to get this app to respond while it is asleep, I have it firing on setInterval, a geolocation listener and a pause listener. I did try idleTimerDisabled, but that had no effect. I also searched the FAQ's here, but was not able to find a definitive answer to this question.

Is it possible for me to get this to work? This app needs to function the same in both Android and iOS. It is very important that I am able to do this on both platforms.

— asked October 11th 2010 by John Feig
  • android
  • background
  • locked
  • mobile
  • sleep

2 Answers

  • Accepted Answer

    At the moment only background audio is supported, everything else (background processing, local notifications, geolocation etc) are slated for the 1.5 release of Titanium Mobile.

    I can not speak for Android, but this is at least the case for iOS support, which is usually ahead of android support by a little.

    How far is that away? I'm not sure if even Appcelerator know. Currently the bug tracker shows 33% completion but issues are being added as quickly as they are being fixed. I think the aim with 1.5 is to have a really solid release with hardly any bugs, before moving forward into 1.6 and beyond. 1.5 was supposed to drop in late September, so I have no idea how far it is away.

    Hope that helps out a bit.


    — answered October 11th 2010 by Angus Peart
    • Could you be a bit more specific about what you mean by 'background'? Do you mean while the phone is locked? when the user navigates away from the app? or both?

      — commented October 11th 2010 by John Feig
    • I interpret 'background' as whenever the app is not in the foreground, so whenever it is not in view. This would include when the device is locked and when the user navigates away from the app. What Appcelerator means by 'background' I can only speculate on.


      — commented October 11th 2010 by Angus Peart
    • Angus, great summary of what's going on. In this case, true background is only available as an Android Service or say a repeating Alarm that fires a PendingIntent. The flag I have on audio currently simply ignores resume/pause when the particular Activity ("heavyweight window") is resumed and paused. If your application get's killed by the OS because it needs resources it'll go away faster in the app than in a service.

      There will still be issues post 1.5 but we're really working to get a lot of Android features in and stable. So that people can start to write best of breed apps.

      — commented October 12th 2010 by Don Thorp
    • Angus, I appreciate the detailed explanation, it was very helpful. Thank you.

      Don, I was looking for the 'official word' on this and you've given it. Thanks.

      — commented October 12th 2010 by John Feig
  • This threat might be interesting for your project.

    — answered October 11th 2010 by Peter Griffin
    1 Comment
    • Thanks for the reply.

      I had seen that thread before, but it seemed ambiguous to me. I have read in different threads different things about what happens when the phone is locked. Also, running in the background could mean two things, either that it runs while the phone is asleep, or that the app constantly runs as a daemon, regardless of the user navigating away from the app. The dev who posted the question in the linked thread wants to do both, and the answer was ambiguous as to what functionality would be supposedly added to 1.5.

      — commented October 11th 2010 by John Feig
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.