earsonheart
earsonheart

Reputation: 1052

Scheduling service on boot and on first app launch

I want to schedule my service to update some data, I need it to be scheduled on boot^ but if user launches my app at first, I would like to schedule my service too. I want to use AlarmManager fo this. Is there way to recognize, is my service has been already scheduled?

Upvotes: 0

Views: 165

Answers (2)

njzk2
njzk2

Reputation: 39397

Use AlarmManager.cancel() to cancel your previously scheduled service (it won't do anything if nothing was actually scheduled, so you can call it anyway) and then schedule your service as you would normally do

Upvotes: 1

jsmith
jsmith

Reputation: 4897

Just catch the ACTION_BOOT_COMPLETED intent and do your registration then. Not in onCreate().

Upvotes: 0

Related Questions