What is the best way to schedule a job in response?

There are various ways to run tasks in the background in Android and iOS, respectively. I found What is the best way to schedule a task in android? as well as stack overflows.

I am wondering which one is best used only by react-native . Would it be enough to use setInterval or setTimeout for tasks that should be performed daily or every few hours?

Won't these tasks be killed by the OS?

Any ideas or suggestions?

+16
source share
2 answers

I will answer my question to find out if this information can be used by anyone who is looking for it.

Since various mobile OSs usually kill background jobs or block them to save battery power, there are several deterministic methods for scheduling tasks in response mode. I use a combination of the following:

Beware of dragons: your application may be closed if it misuses runtime or memory usage after waking up the system. You may need to re-wet all listeners after the phone is left without a battery. Thus, the user still needs to interact intensively with your application.

Update : With Android O, there are very strict restrictions on background execution. When using the HeadlessJSTask service, make sure that it is running as a foreground service if you want it to last longer than a few seconds. This may require notification with him. Please note that only downloading a package may take up to several seconds, depending on your application and device.

+18
source

In fact, there is not enough way for this. but we can mark mauron85 as a way that is better than others on Android, but it also does not work on iOS . for example, if the application was killed by the user, the task will not work, or there will be no control over the number of completed tasks, the task starts every time the device changes its position.

other components, such as act-native-background-fetch and Reaction-native-background-task, have a time limit for the task (the task is repeated every 15 minutes, and there is no way to reduce this period of time), and they just work on Android ,

it would be great if Facebook reacted natively with some practical solution to this problem.

0
source

All Articles