title: How to have a timer running in background to perform an operation after certain periods?
body: <p>I have a button which has a limit of 5 per day and 30 per month. Every time it is clicked it is reduced by 1 from the daily remaining and monthly remaining. Once it has been clicked 5 times, the remaining clicks per day are 0 and he monthly remaining is 25. How do I reset this counter every 24 hours back to 5 in the background, even whilst the app is not running or the device is not turned on. And how do I do the same for after 30 days (month). Currently, I am using SharedPreferences to update the values when I want to. But I want this to happen periodically not every time the app is launched</p>
  
  <pre><code>sharedPreferences.edit().putInt("dailyRemaining", dailyRemaining).apply(); //5
  sharedPreferences.edit().putInt("monthlyRemaining", monthlyRemaining).apply(); //30
  </code></pre>