Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is WorkerManager a realiable way to implement alarm/reminder feature in the app?

We notice that AlarmManagerCompat alone, isn't a reliable way to implement alarm/ reminder feature in our app, due to different AlarmManager behaviour in different version of OS. (For instance, Doze mode)

Initially, we plan to use Evernote's android-job library, to help us implement alarm/ reminder feature in our app.

However, along the way, we also notice that Google just release WorkerManager.

So far, WorkerManager works well for us, when we run some one-time background jobs (Almost immediate, with internet connectivity constraint) after the app quit.

We have plan to use WorkerManager to implement alarm/ reminder feature.

I was wondering, how reliable is WorkerManager to implement such feature? Has anyone try it out? We are targeting API 15 and above.

like image 682
Cheok Yan Cheng Avatar asked May 26 '18 20:05

Cheok Yan Cheng


People also ask

When would you use a WorkManager?

Use WorkManager for reliable workWorkManager is intended for work that is required to run reliably even if the user navigates off a screen, the app exits, or the device restarts. For example: Sending logs or analytics to backend services. Periodically syncing application data with a server.

Is AlarmManager deprecated?

IntentService + WakefulBroadcastReceiver + AlarmManager are deprecated with API 26 (Android 8.0 Oreo).

Whats the best tool for handling work that is deferrable and expected to run even if your app restarts?

What is Work Manager? Work Manager is a library part of Android Jetpack which makes it easy to schedule deferrable, asynchronous tasks that are expected to run even if the app exits or device restarts i.e. even your app restarts due to any issue Work Manager makes sure the scheduled task executes again.

What is Android alarm Manager explain with an example?

Android AlarmManager allows you to access system alarm. By the help of Android AlarmManager in android, you can schedule your application to run at a specific time in the future. It works whether your phone is running or not.


1 Answers

WorkManager is not appropriate for anything that must fire at a specific time as jobs, including those used by WorkManager or android-job, will not fire while the device is dozing.

For exact timing, you should absolutely be using AlarmManagerCompat and specifically, setExactAndAllowWhileIdle() which fires an alarm at exactly the specified time on all API levels.

As your exact timed alarm can and will happen while the device is dozing, your app should not require network connectivity to post your alarm/reminder notification. Ideally, the information should be in the PendingIntent itself and not even need any database fetch/etc.

like image 71
ianhanniballake Avatar answered Nov 16 '22 00:11

ianhanniballake