title: Starting an Android service with AlarmManager and Broadcast Receiver
body: <p>I have a background Android service. It runs in background, checks an URL for some results. And if results change, app sends a notification to user. I want this service to run every 3 hours. My problem is when and how to start the service ?</p>
  
  <ul>
  <li>General behaviour is to create a Broadcast receiver.  </li>
  <li>Then start service when receiver gets a <code>ACTION_BOOT_COMPLETED</code>.  </li>
  <li>Also when receiver gets a boot completed, receiver will use AlarmManager and will create an alarm to run every 3 hours.  </li>
  </ul>
  
  <p>But after installing the application, what if the user doesn't restart his/her phone ?  If user doesn't boot, AlarmManager won't create an alarm.</p>
  
  <ul>
  <li>So another option is to create alarm when user first runs the application.  </li>
  <li>What if user restarts the application ? Should I cancel all previous alarms with <code>AlarmManager.cancel</code> and recreate the alarms ?</li>
  </ul>
  
  <p>So in which conditions do you set alarms for your Android applications ?</p>