Reputation: 16691
I have a checkbook tracking application that allows to set an allowance and spending period for an account, for example $100/week, or $200/month.
I store the data in a table AccountSpendingPeriods
like this:
| _id | account_id | start_date | end_date |
When the user creates an account, I use the current date as a start date and use their spending period to determine the end date. I am running into an issue trying to figure out how/when to add a new row to that table when a new spending period arises.
I looked into an AlarmManager, but I noticed in the documentation it only had intervals up to each day. I want the user to have spending periods for:
So depending on the spending period selected, I may need to update the database at different intervals. Is this possible with an AlarmManager? How can I handle the cases that exceed 14 days? A month cannot be considered as simply 30 days, because they are not consistent throughout the year.
Upvotes: 0
Views: 138
Reputation: 451
I can see a couple of different options.
One way is to use AlarmManager on a daily basis, but in your broadcast receiver determine whether anything actually needs to happen, perhaps recording the next period start date in a preference or table.
So for a weekly period, you record today + 7 days in the metadata table. Your broadcast receiver would then check the date against the preference and either do nothing, or insert the required row and update the next period start date.
So on for the remaining options. This allows you to determine by whatever logic you desire for the intervals.
Another option is to simply set once off alarms using set() or setExact() and each time it fires, set the next alarm at the required interval.
Upvotes: 3