Reputation: 104
What is the best approach to implement a service which executes every 15 mins. Execution should happen when app is killed / in the background and even when it's running. It should do some http work which is already works fine but with asynctask. If this http returns with a particular data, it should show a notification. How should i do this? Any help is greatly appriciated. I'm fine if you just mention approaches, methods, patterns, best practices, etc..
Thank you!
Upvotes: 0
Views: 2315
Reputation: 966
What is the best approach to implement a service which executes every 15 mins.
Using the Job Scheduler. Information on job scheduling can be found at the Intelligent Job-Scheduling documentation. However, be aware that you can't be 100% sure that your service is going to run exactly every 15 minutes as its execution can be affected by the Doze mode and its restrictions.
For the notification part, you build your notification as you would normally do.
If you need more info, you may view the Using the Android Job Scheduler and Background work with JobScheduler videos and check this sample project. Also, one relevant question regarding the repetitive nature of the service can be found here.
Upvotes: 2