1Dan
1Dan

Reputation: 41

Repeatedly background task ionic framework

I'm using ionic-framework / cordova for building my app. I've installed this plugin cordova-plugin-background-mode for working in background mode.

Q: But now how can I do a task that repeats every 30 minutes in background?

Do you know another plugin that does this?

Thanks

Upvotes: 4

Views: 8193

Answers (2)

Giancarlo Ventura
Giancarlo Ventura

Reputation: 183

You can use $timeout and $interval for this task with centain period of time

Angular doc for interval

Upvotes: -2

0x1ad2
0x1ad2

Reputation: 8062

According to the repository that you used the code must look like this:

// Run when the device is ready
document.addEventListener('deviceready', function () {

    // Android customization
    // To indicate that the app is executing tasks in background and being paused would disrupt the user.
    // The plug-in has to create a notification while in background - like a download progress bar.
    cordova.plugins.backgroundMode.setDefaults({ 
        title:  'TheTitleOfYourProcess',
        text:   'Executing background tasks.'
    });

    // Enable background mode
    cordova.plugins.backgroundMode.enable();

    // Called when background mode has been activated
    cordova.plugins.backgroundMode.onactivate = function () {

        // Set an interval of 30 minutes (1800000 milliseconds)
        setInterval(function () {

            // The code that you want to run repeatedly

        }, 1800000);
    }
}, false);

Upvotes: 8

Related Questions