android alarm on specific days
-
19-06-2021 - |
سؤال
I am making app which uses alarm , which is to be triggered on days specified by the user i.e there are check boxes of days(mon, tue, wed, thu, fri, sat, sun)
I have searched a lot on this question, the only solution i came to know is to trigger different alarms using AlarmManager. its mean if user checks all the 7 boxes, i have to trigger alarm 7 times, and to cancel all 7 pending intents if user cancel one alarm?
my question is , is there any other efficient way to handle this issue??
thanks
المحلول
I will assume that you want to trigger the alarm at the same time (let's say 12:00 am) no matter what day is it as long as the day is checked
. Based on that you can:
- have seven different Boolean sharedPreferences for each day.
- Set the AlarmManager to be triggered daily at 12:00 am.
- When the AlarmManager is triggered, you get the day and check if it is checked:
- If yes, then do your thing.
- If no, do nothing.
لا تنتمي إلى StackOverflow