DedrisFrameworkDedrisFramework

← Plugins  /  Background Mode

🌙

Background Mode

cordova-plugin-background-mode
iOS Android

This community plugin keeps your app running after it moves to the background, instead of being paused by the OS. It's useful for music players, trackers and timers that need to keep working while the user is in another app.

⚠️ Use sparingly. Background execution drains battery and is closely policed by app stores. Enable it only when your app genuinely needs to keep working off-screen, and tell the user why.

Installation

terminal
cordova plugin add cordova-plugin-background-mode

API

The plugin is exposed as cordova.plugins.backgroundMode after deviceready:

MethodDescription
enable() / disable()Turn background mode on or off.
isActive()Returns true while the app is actually running in the background.
on(event, cb)Listen for enable, disable, activate, deactivate or failure.
setDefaults(options)Configure the Android foreground notification (title, text, icon, silent).

Usage example

Enable background mode and keep a timer ticking once the app is hidden:

www/js/app.js
document.addEventListener("deviceready", onReady, false);

function onReady() {
  var bg = cordova.plugins.backgroundMode;

  bg.setDefaults({ title: "DedrisApp", text: "Running in the background" });
  bg.enable();

  bg.on("activate", function () {
    console.log("Now in the background — keep working");
  });
}

Tips

📚 Source: the technical reference on this page is based on the cordova-plugin-background-mode project (Apache-2.0 / MIT), maintained by the open-source community and listed in Ionic Native. Descriptions and examples have been rewritten in DedrisFramework's own words. This plugin is not part of the Apache Cordova core.
← Back to plugins Start a project