Closed vtoupet closed 1 year ago
scheduleTask
does not have an option minimumFetchInterval
. That is for the built-in, recurring fetch task.
scheduleTask
uses delay
.
There is nothing preventing the usage of minimumFetchInterval
with scheduleTask. The underlying java method expect a BackgroundFetchConfig
object and uses more or less the same mechanism as the configure
method.
I think that would be great to be able to create custom tasks that can benefit from the JobService for Android SDK >= LOLLiPOP. It would require minimal changes when computing interval value in BGTask
class. Something like the following (in the function schedule
of the BGTask
class):
long interval = 0;
if (config.isFetchTask() || (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !config.getForceAlarmManager())) {
interval = TimeUnit.MINUTES.toMillis(config.getMinimumFetchInterval());
} else {
interval = config.getDelay();
}
What do you think?
There is nothing preventing the usage of minimumFetchInterval with scheduleTask
It doesn't make sense to use the word "minimumFetchInterval
" with the method scheduleTask
. scheduleTask
uses delay
.
Anyway, it's not necessary since scheduleTask
already uses JobScheduler
by default. It only uses AlarmManager
when configured with forceAlarmManager: true
.
The config option is named forceAlarmManager
to communicate to the developer that JobScheduler
is the implied default and you must "force" the SDK to use AlarmManager
.
Ok, I get it, thanks @christocracy.
2 other things (let me know if you want me to create other issues).
cancel
(there is a comment in your code). What happens when we update the config of the same taskId without cancelling?Your last two points are fair. Go ahead and post two separate issues for those.
btw, if you are using Typescript, the linter should flag using minimumFetchInterval
with the method scheduleTask
, which accepts TaskConfig
I actually don't use scheduleTask in react-native side but rather in the Java side (from a pure Java Android widget configuration screen). So I am using this instead:
BackgroundFetchConfig.Builder config = new BackgroundFetchConfig.Builder();
config.setTaskId(taskId);
config.setIsFetchTask(false);
config.setDelay(TimeUnit.MINUTES.toMillis(interval));
config.setPeriodic(true);
config.setStartOnBoot(true);
config.setStopOnTerminate(false);
config.setJobService(JOB_SERVICE_CLASS);
config.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
BackgroundFetch adapter = getAdapter(context);
adapter.scheduleTask(config.build());
But my application is react-native. It's not conventional. I did not introduce it to you like this as you would have probably told me that t is out of the scope of this library ;-)
Your last two points are fair. Go ahead and post two separate issues for those.
Do you want me to create the issues in this repository or the native one (https://github.com/transistorsoft/transistor-background-fetch)
Native one. The native lib is common to this RN version in addition to the Cordova, Capacitor and Flutter versions.
Your Environment
react-native -v
): 0.70.5The basic BackgroundFetch is configure in a useEffect at startup only:
on index.js, the headless task is properly registered.
The problem comes from custom tasks. When a task is scheduled like this:
I get this from logcat output:
Expected Behavior
I would expect to see 15 minutes as the requested interval in
JobInfo
Actual Behavior
Instead of using
minimumFetchInterval
value to configure the interval, it is using the delay which is incorrect when forceAlarmManager is set to false.I think the problem comes from the transistor-background-fetch library: this line:
long interval = (config.isFetchTask()) ? (TimeUnit.MINUTES.toMillis(config.getMinimumFetchInterval())) : config.getDelay();