BackgroundFetch not working on android when app is terminated

The task gets registered it also works.When in recent apps it works.When gets deleted it stops working!

Expo CLI 3.11.3 environment info:
OS: Windows 10
Yarn: 1.21.0 - C:\Users\Steve\AppData\Roaming\npm\yarn.CMD
npm: 6.9.0 - E:\Program Files\nodejs\npm.CMD
Android Studio: Version AI-191.8026.42.35.5900203

SDK version : 36.0.0
Standalone app on android 7

Just to confirm I was right I went into my apps background in my setting in my phone,I can see the app is in background progress.As soon as I remove it from recent apps it gets gone from the background progress too.So everything is as I described and no doubts about it.I also have used:

stopOnTerminate: false,

But it doesn’t do anything.

Here’s a function that does register the tasks and everything:

import * as BackgroundFetch from 'expo-background-fetch';
import * as TaskManager from 'expo-task-manager';
export async function registerFetchTask(taskName, jobCallback, interval) {
    TaskManager.defineTask(taskName, jobCallback);

    const status = await BackgroundFetch.getStatusAsync();
    switch (status) {
        case BackgroundFetch.Status.Restricted:
        case BackgroundFetch.Status.Denied:
            console.log("Background execution is disabled");

        default: {
            console.log("Background execution allowed");

            let tasks = await TaskManager.getRegisteredTasksAsync();
            if (tasks.find(f => f.taskName === taskName) == null) {
                console.log("Registering task");
                await BackgroundFetch.registerTaskAsync(taskName,{
                    minimumInterval: 60,
                    stopOnTerminate: false,
                    startOnBoot: true,

                tasks = await TaskManager.getRegisteredTasksAsync();
                console.log("Registered tasks", tasks);
            } else {
                console.log(`Task ${taskName} already registered, skipping`);

            console.log("Setting interval to", interval);
            await BackgroundFetch.setMinimumIntervalAsync(interval);

Inside app.js I call:


The fetchServer will add things to my database on my laptop.So I can see if the app is running the task I’m getting new rows in the database.

Update:When removing app from recent apps it gets gone from Apps in background in setting after a while I see the app back in Apps in background in my device setting.But the task won’t run anymore.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.