To make some action for some time I found that there are several choices:
What is big difference of all this? What is the best practice of making schedule action?
There are several APIs available to schedule tasks in Android: Alarm Manager. Job Scheduler. GCM Network Manager.
Schedule a Routine for when you need it, or start it whenever you want, and Google Assistant can automatically do multiple actions.
Guaranteed: The task runs even if the device restarts. Guaranteed work means that the task will run if the application process is killed or the device is restarted. Thus, an important example for WorkManager would be backing up pictures to a server. This work can be deferred, but it should be guaranteed to run as well.
AlarmManager
is the global "Timer", this man can wake your application up, even if it wasn't started. Heavy guy.ScheduledExecutorService
: standard Java way to do some scheduled stuff, used in JSE, simple and familiar for Java developers. The job will be executed in different thread than UI or thread that schedule this job. Well suited for services not to deal with UI and to proccess long and heavy stuff.Handler
: Android way to schedule job, job executes in UI thread (if the handler was created in UI), so it cannot be very heavy proccessing or it'll just freeze your UI.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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With