Reputation: 184
I'm looking for a way to run task or service when the app is closed (not in background state), I tried to use Headless JS and JobScheduler but that didn't seem work for me. My task is about fetching data from server and push notification in some conditions. Any help.
Upvotes: 2
Views: 3064
Reputation: 343
If HeadlessJS doesn't work for you then you indeed need to use native code.
Using Android's native JobScheduler as mentioned here: JobScheduler documentation
definitely works. You can schedule periodic task with specific interval and optional conditions (like active internet connection). Don't forget to define required services in your manifest just like you would in pure native Android application. You can use MainActivity/MainApplication entry points to define your jobs.
Your jobs will be fired regardless of ReactNative part of your application is running or not. Local notifications can be displayed even from background job like these.
Upvotes: 1