Device manufacturer / model: Android Studio Emulator
XCode version: N/A
Capacitor info (npx cap doctor): Using capacitor version 5
Plugin config provided to BackgroundFetch.configure:
const status = await BackgroundFetch.configure(
{
minimumFetchInterval: 15,
stopOnTerminate: false, // <-- required
enableHeadless: true, // <-- required
},
async (taskId) => {
console.log("[BackgroundFetch] EVENT:", taskId);
// Perform your work here
await sendData();
console.log("[BackgroundFetch] work complete");
// Signal to the OS that your work is complete
BackgroundFetch.finish(taskId);
},
async (taskId) => {
console.log("[BackgroundFetch] TIMEOUT:", taskId);
// Signal to the OS that your work is complete
BackgroundFetch.finish(taskId);
}
);
Expected Behavior
i want to send call a function even if the app is killed. and this function should be run continuously after 10 or 15min
const sendData = async () => {
console.log("send data ran");
try {
const data = {
name: "doe",
age: 26,
};
const response = await axios.post("http://10.0.2.2:8000/postUser", data);
console.log(response.data); // Handle the response data
} catch (error) {
console.error(error); // Handle the error
}
};
Actual Behavior
shows error
FATAL EXCEPTION: main
and does not run the function.
Steps to Reproduce
N/A
Context
i want to run a function after every 10 or 15min even app is completely terminated.
Debug logs
FATAL EXCEPTION: main
Process: com.ionic.app, PID: 25019
com.transistorsoft.tsbackgroundfetch.BGTask$Error: com.ionic.app.BackgroundFetchHeadlessTask
at com.transistorsoft.tsbackgroundfetch.BGTask.fireHeadlessEvent(BGTask.java:231)
at com.transistorsoft.tsbackgroundfetch.BGTask.onTimeout(BGTask.java:196)
at com.transistorsoft.tsbackgroundfetch.BGTask$1.run(BGTask.java:80)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Your Environment
npx cap doctor
): Using capacitor version 5BackgroundFetch.configure
:Expected Behavior
i want to send call a function even if the app is killed. and this function should be run continuously after 10 or 15min
Actual Behavior
shows error FATAL EXCEPTION: main and does not run the function.
Steps to Reproduce
Context
i want to run a function after every 10 or 15min even app is completely terminated.
Debug logs
FATAL EXCEPTION: main Process: com.ionic.app, PID: 25019 com.transistorsoft.tsbackgroundfetch.BGTask$Error: com.ionic.app.BackgroundFetchHeadlessTask at com.transistorsoft.tsbackgroundfetch.BGTask.fireHeadlessEvent(BGTask.java:231) at com.transistorsoft.tsbackgroundfetch.BGTask.onTimeout(BGTask.java:196) at com.transistorsoft.tsbackgroundfetch.BGTask$1.run(BGTask.java:80) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)