Closed noumankhan95 closed 2 weeks ago
When simulated task runs fine, see https://dontkillmyapp.com
it doesn't run even once and in simulation it says job forced
does .configure automatically run the job every 15 mins and if so whts the purpose of enabling headlessjs , i didn't understand documentation
it says job forced
Yes, of course it does. It's normal for simulated tasks.
does .configure automatically run the job every 15 mins
.configure(config)
initiates an Android periodic task according to Config.minimumFetchInteval
.
and if so whts the purpose of enabling headlessjs , i didn't understand documentation
Because you do not understand the nature of the "Android Application/Activity Life-cycle"; you do not understand how a React Native app renders its UI within the MainActivity
and when an Android app is "terminated", it's the MainActivity
which is terminated. When an app is launched "Headless", only the Android Application
is launched (without a MainActivity
), thus your RN application code does not exist in that state.
Only the code in your index.js
exists, which is where events from background-fetch are routed in the terminated state. Thus, that is why you must .registerHeadlessTask
to receive events in the Android terminated state.
If simulated tasks operate correctly, it is proven that the plugin is setup and configured correctly. The issue is with your device and settings.. see https://dontkillmyapp.com
Another name for “headless” is “Activity-less”. The Android MainActivity
(where your RN App instance lived) is “the head”.
im surprised even when i schedule a task it doesnt run , is this issue known on android 9 ?
useEffect(() => {
initTask().then(s => console.log("status", s)).catch(e => console.log("u init", e))
// Clean up the background fetch when the component unmounts
BackgroundFetch.scheduleTask({
taskId: 'com.example.mytask',
delay: 500,
periodic: true, // Set this to true to repeat the task
stopOnTerminate: false,
startOnBoot: true,
}).then(s => console.log("s", s)).catch(e => console.log("schedule error", e));
}, []);
well, you'll never get a task to run with a delay: 500
, especially not without forceAlarmManager: true
and even then the best you'll get is 1000ms
.
The Android plugin uses JobScheduler
by default (which is subject to “Doze Mode”. With forceAlarmManager: true
, the plugin uses AlarmManager
.
With forceAlarmManager: true
, you CANNOT simulate tasks.
Without forceAlarmManager: true
, the fastest interval you'll ever see is about every 15 minutes.
I saw, that in case the headless background task fails (e.g., because of an exception as in my case), the scheduled job stays in state waiting. You need to force a timeout first, before you can run it again.
adb.exe shell cmd jobscheduler timeout <your.package.id> 999;
adb.exe shell cmd jobscheduler run -f <your.package.id> 999;
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Also i need to know wether the .configure will fire events after every 15 minutes and so and do i need to enable headlessJs for just checking time in background and muting or setting it to normal. i want it the task to keep running even when app is terminated
Your Environment
react-native -v
): 0.72.4Expected Behavior
The task should be running in background every 15 minutes even when app is terminated but it doesnt run even once
Actual Behavior
the task is not running in background , it works when i simulate the event , it says job forced but not without simulation
Context
I am trying to change my phone to vibration or normal mode
Debug logs