tags:

views:

138

answers:

2

To make some action for some time I found that there are several choices:

  1. use AlarmManager
  2. use ScheduledExecutorService
  3. use Handler's method postDelayed

What is big difference of all this? What is the best practice of making schedule action?

+4  A: 

Hello,

  1. AlarmManager - is the global "Timer", this man can wake your application up, even if it wasn't started) Heavy guy.
  2. ScheduledExecutorService - standart java way to do some sheduled stuff, used in JSE, simple and familiar for java developers. The job will be executed in different thread than UI or thread that shedule this job. Well suited for services not to deal with UI and to proccess long and heavy stuff.
  3. Handler - Android way to shedule job, job is executing in UI thread(if the handler was created in UI) so it cannot be very heavy proccessing because it can just freeze your UI).
ponkin
+2  A: 

AlarmManager is independent of your app and guarantees that the task will run.
The other two run as a part of Activity/Service with according life cycle restrictions (e.g. can be killed anytime).

alex