android - Difference between AlarmManager and ScheduledExecutorService -
besides setting , exact time (i.e. midnight) versus setting delay (i.e. 24 hours), what's difference between using alarmmanager
, scheduledexecutorservice
run task periodically?
in case, need run little bit of code check new data every night , create new notification if there new data.
thanks!
scheduledexecutorservice
runs in application process. if application process dies, none of scheduled tasks run. hence need service
(so process lives beyond activities active part of lifecycle).
while alarmmanager
critical system service runs time. , if application scheduled , killed, alarmmanager
may start application again (via pendingintent
).
and last major difference no 1 mentioned here alarmmanager
knows wakelock
s , power management. means alarmmanager
may wake android device @ specified time run scheduled task. while scheduledexecutorservice
knows nothing power management , start task when device not in deep sleep (i.e. can miss time).
Comments
Post a Comment