How to Run Your App in Background

Environment

Service Code (AppBuilder), Telerik Platform General
Mobile development type Hybrid (Apache Cordova app)

Description

Your app needs to execute tasks on specified intervals when running in the background.

Solution

Given the differences in the means iOS and Android are granting to apps for working in the background there may be different approaches to do so. You will usually need a Apache Cordova plugin to register and execute your code in the background and ensure that the strict requirements and guidelines of the respective OS are met.

iOS has a set of defined modes for background activities which your app should specify to be allowed to run tasks in the background while the app is suspended (for example, playing audio, tracking location, etc.). You can read more about the subject in App Programming Guide for iOS — Background Execution. The supported modes are listed the UIBackgroundModes section here. To be able to use the background mode you need a plugin that incorporates such logic in it (JavaScript code without the native support via a plugin will not execute when the app enters in the background) and registers the correct background mode for this. For example, one such implementation is the popular in the community Cordova Background Geolocation plugin. A similar one is the Cordova BackgroundFetch plugin for iOS.

On Android this can be done via a plugin that is registering a service implemented with native code. A popular option for Android in the community is the Cordova Background Plugin (while it may not be compatible with the App Store requirements for using background modes).

Notes

Even that the app is allowed to run in the background the OS may determine that the background tasks are too intensive, frequent or battery-heavy and interrupt them. Ensure that you are using the correct plugin and native code implementation and required configuration for your task if you need to run a background task.

In many cases it may be sufficient to run your code using the application life-cycle events when the app is paused or resumed, or use push notifications or local notifications for the purpose.

Community plugins may not be compatible with the vendor stores and requirements for background execution. Consult the respective plugin and functionality documentation and the purpose of the plugin beforehand.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.