WorkManager API for Exact time execution [duplicate]
Asked Answered
K

2

8

I want to send offline notification to user periodically at exact time (assume daily 9:00 AM). Right now I was trying workmanager Api but not able to find any method like AlarmsManager's setExact or setexactandallowwhileidle.

Only repeatInterval option is there that will be 24 (daily) in my case but how to send notification at exact time (9 : 00 am) .

Knotted answered 20/6, 2018 at 10:2 Comment(0)
P
12

WorkManager isn't a replacement for AlarmManager. For your use case, AlarmManager sounds like the right solution. WorkManager is for deferrable tasks, not for executation of tasks at an exact time or while the system is in a low-power, idle mode such as doze mode.

Patience answered 20/6, 2018 at 20:5 Comment(0)
Q
0

You can do with help of workmanager also. For that you have to calulate delayedtime between current time and next day's fixed time(in your case 9 AM). For details see this answer -> show notification using workmanager api

Note: Workmanager execution can not be fixed, it depends on system at given point of time.

Quadratics answered 16/4, 2019 at 11:20 Comment(2)
yeah it will work but for making it periodic in the end again you have to depend on Alarm Manager. After my research I can say Alarm manager is best available API for perform any operation (repeat/single) based on fix/random time.Knotted
@AyushJain Alarm manager is not the best solution imo, because it shows alarm icon in the statusbar. So user may get confused if he didn't put any alarm in his phone.Hhour

© 2022 - 2024 — McMap. All rights reserved.