0

In my use case user can schedule a task at any date and time and when the time approaches if user is active(or app is at foreground) the task will start automatically if not a notification appears to begin the task

i have almost achieved that with react native push notification library i'm able to schedule a local notification but there is no support for on receive of scheduled local notification(https://github.com/zo0r/react-native-push-notification/issues/1662) so when using this library even when app is active user have to click the notification to start the task

is there a way to properly schedule a task such that if app is active at that time it has to automatically start the task

Dheeraj
  • 240
  • 2
  • 8
  • 1
    Does this answer your question? [What is the best way to schedule a task in react native?](https://stackoverflow.com/questions/39946431/what-is-the-best-way-to-schedule-a-task-in-react-native) – and_dev Sep 24 '20 at 16:25
  • No i don't have anything to run in background even if i use background setTimeout in my case a user can schedule n number of schedules and user may kill app completely which stops the timeout which is not efficient and reliable – Dheeraj Sep 24 '20 at 16:39

1 Answers1

1

One possible solution could be to save tasks locally using AsyncStorage.

Then you could use react-native-background-timer for background code execution. More on this.

Then you will be able to periodically check AsyncStorage for tasks. Each task would have a hh:mm value. If current time would be the same as one event then you would execute some code.

When times are equal you could check for AppState and react :P based on that.

I have no experience with background timer so I cannot guarantee validity of this solution.