title: Periodically run a service in the background
body: <p>We are designing an app that users use on a subscription basis. When the user pays for a particular period, a receipt is issued from our server valid for the duration. The app is designed to be used "offline", so it will only be connecting with the internet to get the receipt from the server. </p>
  
  <p>When in "offline" mode, the app waits for the paid duration #-of days until it requires the user to pay again. We are having problems implementing this. </p>
  
  <p>We first tried to use an always running background service. But after reading <a href="https://stackoverflow.com/a/2682130/5753416">https://stackoverflow.com/a/2682130/5753416</a>, <a href="http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/" rel="nofollow noreferrer">http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/</a>, we decided to use AlarmManger to schedule periodic alarms to check for the payment.</p>
  
  <p>We are now facing problems with the alarm when the user changes the time/date. We are listening to <strong>Intent.ACTION_TIME_CHANGED and Intent.ACTION_DATE_CHANGED</strong> broadcast, but that isn't being <strong>broadcast</strong> when setting the date to the <strong>past</strong>. </p>
  
  <p>My question is what is the right way of implementing a similar functionality. Any advice is appreciated.</p>
  
  <p><strong>edit</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/21758246/android-action-date-changed-broadcast">issues with the broadcast </a></p>
  
  <p><a href="https://code.google.com/p/android/issues/detail?id=2880" rel="nofollow noreferrer">ASOP bug issue</a></p>