title: Android : how to make sure AlarmManager are not crash first AlarmManager are haven't finish execute?
body: <pre><code>public class AlarmManagerClass extends BroadcastReceiver 
  {    
      public static boolean haveInternet(Context ctx) {
  
          NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx
                  .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
  
          if (info == null || !info.isConnected()) {
              return false;
          }
          if (info.isRoaming()) {
              // here is the roaming option you can change it if you want to
              // disable internet while roaming, just return false
              return false;
          }
          return true;
      }
  
  
       @Override
       public void onReceive(final Context context, Intent intent) 
       {   PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
       PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
       wl.acquire();
  
       // Put here YOUR code.
       Log.d(null,"Alarm !");
       Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For example
  
              Thread falador = new Thread() {
                   @Override
                   public void run() {
                       while (haveInternet(context)==false){
                           try {
                              sleep(60000);
                              if (haveInternet(context)==true){
                                  PostSync(context);
                                                      return;
                              }
                          } catch (InterruptedException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                       }
                   }
            };
                falador.start
              Log.d(null,"Alarm Exit !");
       wl.release();
       }
  
   public void SetAlarm(Context context)
   {
       AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
       Intent i = new Intent(context, AlarmManagerClass.class);
       PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
       am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute
   }
  
  }
  </code></pre>
  
  <p>I have an AlarmManager that will <code>PostSync();</code> every 10 Minutes, where <code>PostSync</code> is the function to synchronize data to the server.</p>
  
  <p>For example :<br>
  After 10 minutes the AlarmManager wakes up, and checks if there is a network connection or not. If there is no connection, it will check again by 60 second later.</p>
  
  <p>So, whenever it doesn't have internet connection in 10 Minutes, the first AlarmManager's Task haven't finish executing, because it is waitng for an internet connection. The second AlarmManager wakes up and checks whether it <code>haveInternet</code> or not, if it doesn;t it will sleep for one minute, etc. So, this is the infinity circle....will this happen on this code?  </p>
  
  <p><strong>How to make sure if the first AlarmManager's Task are haven't finish execute, do not wake up the second AlarmManager?</strong></p>