title: Android: Alarms and IntentServices
body: <p>After lots of research on implementing IntentServices and Alarms together, I've come up with this. I don't know exactly what happens with this code so I need help in knowing exactly what is going on.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class MainActivity{
    
    //....
  
      public void onNewItemAdded(String[] _entry){
              
              //...
  
             Intent intent = new Intent(MainActivity.this, UpdateService.class);
           startService(intent);
      }
  
    //....
  }
  
  public class AlarmReceiver extends BroadcastReceiver {
   @Override
   public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Intent startIntent = new Intent(context, UpdateService.class);
    context.startService(startIntent);
        }
      public static final String ACTION_REFRESH_ALARM = "com.a.b.ACTION_REFRESH_ALARM";
  }
  
  public class UpdateService extends IntentService{
    //...
    @Override
   public void onCreate() {
    super.onCreate();
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    String ALARM_ACTION = AlarmReceiver.ACTION_REFRESH_ALARM;
    Intent intentToFire = new Intent(ALARM_ACTION);
    alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
   }
  
   @Override
   protected void onHandleIntent(Intent intent) {
    Context context = getApplicationContext();
    SharedPreferences prefs = PreferenceManager
      .getDefaultSharedPreferences(context);
    int updateFreq = Integer.parseInt(prefs.getString(
      PreferencesActivity.PREF_UPDATE_FREQ, "60"));
    boolean autoUpdateChecked = prefs.getBoolean(
      PreferencesActivity.PREF_AUTO_UPDATE, false);
    if (autoUpdateChecked) {
     int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
     long timeToRefresh = SystemClock.elapsedRealtime() + updateFreq
       * 60 * 1000;
     alarmManager.setInexactRepeating(alarmType, timeToRefresh,
       updateFreq * 60 * 1000, alarmIntent);
    } 
    else {
     alarmManager.cancel(alarmIntent);
    }
    refreshKeywords();
   }
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My aim is to get the refreshKeywords() method to be called every minute. Also, what happens if the onNewItemAdded() method is called more than once?</p>
  
  <p>Sorry if this question is stupid, I'm a beginner.</p>