Is it possible to prevent putting the application into the background?

  • 2
  • Question
  • Updated 8 years ago
I'd like to make my application staying active without going to background unless user quits it or switch to another application.
is it possible to control this at the runtime or by changing any application settings?
Photo of Vadim Lazuko

Vadim Lazuko

  • 7 Posts
  • 0 Reply Likes

Posted 9 years ago

  • 2
Photo of Fil Maj

Fil Maj

  • 139 Posts
  • 15 Reply Likes
Which platform(s) are you targetting?
Photo of Vadim Lazuko

Vadim Lazuko

  • 7 Posts
  • 0 Reply Likes
Android and iOS
Photo of Fil Maj

Fil Maj

  • 139 Posts
  • 15 Reply Likes
I am not 100% sure on iOS (I will get someone to confirm) but on Android, there is one setting in native code that can be changed to tweak some of this behaviour. Currently, this is not exposed in build.phonegap.com but I will make a note of it and update this thread when we deploy the feature.

I will describe the Android feature, in case this is what you are looking for. There is an option on the Android phonegap base class (called DroidGap.java) that specifies whether your app "keeps running in the background." See:

https://github.com/phonegap/phonegap-...

By default, it is true. So JavaScript and things like timers, etc. are still executing if you send your app to the background by switching to another app, or if you hit the HOME button. If you want to turn this option OFF (so pause timers and other execution), you have to do so via native code. Currently can't be done via build.phonegap.com, but it's certainly something we can expose down the road.
Photo of Vadim Lazuko

Vadim Lazuko

  • 7 Posts
  • 0 Reply Likes
Thank you for the reply, however my problem is the opposite. I've noticed that sometimes (not always) my simple application which just listen to a regular geolocation updates (every 1 second) stops and no updates happen.

So I'm looking for a solution to guarantee (or even bring my app to the front when it is going to be put to background) that it will run without interruption until user press Quit button.
Photo of Shazron

Shazron, Developer Level 42

  • 37 Posts
  • 2 Reply Likes
PhoneGap Build will need to modify the project's [PROJECTNAME]-Info.plist to add the values:

<key>UIApplicationExitsOnSuspend</key>
<true/>

Set the second value to true to prevent multi-tasking.
Photo of Vadim Lazuko

Vadim Lazuko

  • 7 Posts
  • 0 Reply Likes
Does that mean I have to add

to my config.xml?
Photo of Vadim Lazuko

Vadim Lazuko

  • 7 Posts
  • 0 Reply Likes
... have to add
-- preference name="UIApplicationExitsOnSuspend" value="false" readonly="true"/ --
Photo of snelson

snelson

  • 18 Posts
  • 0 Reply Likes
I need to do exactly what Vadim is trying to do. Is this possible?

I'd actually like to have the screen turn off, to conserve battery life, but still be able to get gps data and send it to the server. Will the pause event allow me to do this?
Photo of Conrad

Conrad

  • 20 Posts
  • 1 Reply Like
We also want the app to continue logging location while in the background. I've tried using timeouts but when returning to the app, it continues from its previous exit point. The gps accuracy also reduces on pause of the app.