The settings for Ionic backgroundFetch are stagnating and not refreshing

I am currently working on an ionic app with capacitor. My goal is to have my app execute background tasks even after it has been terminated. From what I've gathered in the documentation, this should be achievable by adjusting the following parameter:

stopOnTerminate: false

To test out the backgroundFetch plugin, I set up a basic app and implemented the code snippet below:

    const config: BackgroundFetchConfig = {
      stopOnTerminate: false, // Changing this to true would stop background-fetch when user exits the app.
    };

    this.backgroundFetch.configure(config)
        .then(() => {
          console.log('Background Fetch initialized');

          this.backgroundFetch.finish();

        })
        .catch(e => console.log('Error initializing background fetch', e));

    this.backgroundFetch.start();

Despite these configurations, after building the app and checking the android studio logcat window via Capacitor, I noticed that the stopOnTerminate value did not reflect the change:

com.example.app D/TSBackgroundFetch: {
      "taskId": "cordova-background-fetch",
      "isFetchTask": true,
      "minimumFetchInterval": 15,
      "stopOnTerminate": true, // The intended result was for this to be set as false
      "requiredNetworkType": 0,
      "requiresBatteryNotLow": false,
      "requiresCharging": false,
      "requiresDeviceIdle": false,
      "requiresStorageNotLow": false,
      "startOnBoot": false,
      "forceAlarmManager": false,
      "periodic": true,
      "delay": -1
    }

Is there an additional step required to modify the default settings effectively?

Answer №1

Found a new method to make it functional by altering the way I imported the BackgroundFetch plugin

import BackgroundFetch from 'cordova-plugin-background-fetch';

In addition, I had to include enableHeadless in the configuration options for it to function properly

        // Your background-fetch handler.
        const fetchCallback = (taskId) => {
            console.log('[js] BackgroundFetch event received: ', taskId);
            // Required: Signal completion of your task to native code
            // If you fail to do this, the OS can terminate your app
            // or assign battery-blame for consuming too much background-time
            BackgroundFetch.finish(taskId);
        };

        const failureCallback = (error) => {
            console.log('- BackgroundFetch failed', error);
        };

        BackgroundFetch.configure(fetchCallback, failureCallback, {
            minimumFetchInterval: 15, // <-- default is 15
            stopOnTerminate: false,
            enableHeadless: true // <-- Added this line
        });

Currently making changes to the config in android studio

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can XferMode be specified within a layer-list?

I'm curious if there is a method to designate multiple layers in a layer-list XML file and instruct each layer to blend based on a specific XferMode from PorterDuff. This functionality would be extremely beneficial for creating composite backgrounds ...

Help needed exporting FBX model from Android target during runtime using Unity

I've been developing a runtime FBX exporter for Unity that utilizes the Autodesk FBX SDK. In order to build and run this project on a target, the SDK requires you to have RUNTIME_FBX defined in the scripting define symbols. Everything works fine with ...

Jhipster: Allowing users to effortlessly generate linked objects under their account

My goal is to develop a service that assists individuals in making informed decisions. To achieve this, I must guide users through an onboarding process where they create entities that reflect their circumstances. During data input, I aim to establish lin ...

Ts2532, The existence of the object is potentially unsafe

I am encountering an issue while trying to update a task in my project built with the MEAN stack. Although all APIs are functioning properly, I am facing an error when attempting to patch an element using the ID parameter. The error message displayed is: & ...

Parsing HTML with Retrofit 2.0

Is there a way to efficiently parse HTML using retrofit 2.0 on Android? If not, is it possible to obtain a raw response and handle the parsing manually without going through a converter factory and encountering potential parsing problems? I attempted to u ...

Is TypeScript capable of handling deep partials?

Can a partial type in TypeScript be specified in a way that applies partiality to all child objects as well? For instance: interface Foobar { foo: number; bar: { baz: boolean; qux: string; }; } const foobar: Partial<Foobar> = { foo: ...

I have noticed that the OnInit lifecycle hook is missing from the Angular component file that I've created

After generating a new component file in my Angular project using the command "ng g c 'component name'", I noticed that the OnInit is missing from my component file initially. ...

Retrieve the validation result using `Express-validator .getValidationResult()` function

Struggling with implementing proper validation for a basic web application login system. Despite extensive research on express-validator and scouring resources like npm documentation, tutorials, and Stack Overflow, I am unable to resolve the issue related ...

Issue with Cordova 10 and Android SDK 30: Unable to open local file ("Forbidden to load local resource: file:///storage/emulated/0/Android/data...")

I've encountered an issue while updating my Cordova application to use SDK 30 instead of 29. It seems that the default value of setAllowAccessFile in the webview changed from true to false between Android SDK 29 and 30. Unfortunately, I don't ha ...

In Angular, use the ngFor directive to iterate through items in a collection and add a character to each item except

Currently, I am iterating through my data list and displaying it in the view using spans: <span *ngFor="let d of myData"> {{d.name}}, </span> As shown above, I am adding a comma ',' at the end of each item to ensure a coherent displ ...

Fragment with Two Different Layouts

As a newcomer to Android development, I have a query - can a second layout be added in a Fragment? For example: View2 view2 = inflater.inflate(R.layout.b, container, false); public class d extends Fragment { @Override public View onCreateView(L ...

What is the correct method for retrieving JSONArray elements?

In one of my PHP files, I am retrieving data from a database, converting it to an array, and then encoding it. The purpose is to pass this JSON array to an Android app I am working on for parsing. Below is the PHP file: <?php $response = array(); // ...

Enumeration in zod validation

Currently, I am using a schema in zod and have an object. const escortTypeOptions = [ { value: "Nutrition", label: "תזונה" }, { value: "Training", label: "אימונים" }, { value: "Nutrition ...

Obtaining the MD5 checksum of a file directory in Android/Java: A step-by-step guide

I need to generate an MD5 checksum for a directory of files. I have successfully implemented the algorithm for individual files, but when applying it to a directory, the result is null. How can I efficiently calculate the checksum for the entire directory? ...

Why does the error "property undefined" keep popping up even though I've already declared it?

Currently, I am facing an issue with toggling the theme in my project. I am encountering difficulties with the types involved, and I am unsure whether the problem lies within my TypeScript configuration or my actual code itself. I attempted to replicate t ...

Obtaining Axios response header in a Typescript environment

I am currently working on a rest call that may return a header that I need to store. In order to do this, I have to first check if the header is present before storing it. Here is how I approached it: private getHeader(response: AxiosResponse) { if (r ...

Converting interfaces into mapped types in TypeScript: A guidance

Understanding Mapped Types in TypeScript Exploring the concept of mapped types in TypeScript can be quite enlightening. The TypeScript documentation provides a neat example to get you started: type Proxy<T> = { get(): T; set(value: T): void ...

Adjust a parameter gradually accelerating by continuously pressing a button

I have been pondering this issue for a few days now. I am attempting to create a selector that works with a wide range of numbers within integer limits. The idea is that when a button is held down, the value should change slowly at first and then accelerat ...

Tips for converting NULL% to 0%

When running my calculatePercents() method, I am receiving NULL% instead of 0%. https://i.sstatic.net/NSbls.png Upon checking my console.log, I noticed that the values being printed are shown as NULL. https://i.sstatic.net/A7Jlk.png calculatePercents() ...

Using Javascript to extract the initials of names

I am looking for a way to shorten Person and group names Person : Robert Smith David Smith James Johnson William If I use this code snippet: if(Name.split(",").length === 1) return Name.trim().split(" ").map(x => x[0]).reduce(( ...