Reputation: 21
I have a mobile application that revolves around a timer that counts down on screen and sends various things such as text messages when the timer reaches a certain time along with changing color, vibrating etc etc. Is there a way to keep the app running in the background constantly so that it is not killed off? I am using a PhoneGap service so PhoneGap plugins are an option. I have tried one plugin called "Background Mode" here is the link to the documentation. However this doesn't seem to work 100% of the time.
PhoneGap generates a config.xml, where I can change some of the properties/settings of the app. Here are the propeties/preferences (background related ones) I have defined in the config file.
<preference name="exit-on-suspend" value="false" />
<preference name="KeepRunning" value="true" />
<gap:plugin name="de.appplant.cordova.plugin.background-mode" version="0.5.0" />
Any suggestions would be appreciated.
Thanks.
Upvotes: 0
Views: 5118
Reputation: 116
Sometimes finding the answer involves rephrasing the question. Phonegap/Cordova in the mobile environment is very sensitive how background processes are used as these things can pull on the devices limited resources (battery & data limitations).
Change the way you are approaching this problem and you'll find that phonegap/cordova can give you the tools to accomplish your task.
In general it will be hard to keep an app running in the background for more than fifteen minutes using the phonegap/cordova framework. Timers are almost out of the question. Trust me I tried. When the app loses focus it is suspended and may be shutdown completely if the device needs memory depending what platform you are using.
An alternative approach is to have your server handle the timing issues and send out push notifications that can wake up your app briefly and allow you to process and respond. I've had success using a background fetch method which checks for updates and schedules notifications (some immediate, some to occur later).
Schedule notifications to occur as timed events that would prompt your user to open the app using the third party local notification plugin. Once the user hears and/or sees your notification and opens the app you can perform changes to the display as the app is resumed. See http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html for details on how to handle this event.
I hope this helps.. Good luck with your endevors
Upvotes: 3
Reputation: 86
Try using a service.I think this is what you really need.
Activity may be killed but service will be preserved
(as long as your hardware memory is not consumed by someone else, then service will be killed and restarted if you want)
http://developer.android.com/guide/components/services.html
Upvotes: 1