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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.