Starting and stopping a service using 3 alarms
<p>I want my app to start at 9am everyday. for that I start Alarm_1 using <code>setRepeatingAlarm()</code> that starts at 9am everyday.</p>

<pre><code>manager.setRepeating(AlarmManager.RTC_WAKEUP,
    timeOn.getTimeInMillis(), 86400000,startingIntent);
</code></pre>

<p>From alarm_1, I start another alarm, MainAlarm, that repeatedly starts my service at the interval of 1min.</p>

<pre><code>manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
    SystemClock.elapsedRealtime(), duration, MainActivity.mainIntent);
</code></pre>

<p>I want my app to stop at 9pm everyday. </p>

<p>For that I start Alarm_2 using <code>setRepeatingAlarm()</code> that <code>cancel()</code> MainAlarm everyday at 9pm.</p>

<p>But this is not working as expected. </p>

<p>What should be done? Is there any problem because I am using 3 alarms?</p>

<p>The alarms do not work the next day.</p>

<pre><code>     This is my cancel() code:
          public class AlarmReceiver2 extends BroadcastReceiver {
          @Override
          public void onReceive(Context context, Intent intent) {
         AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
         manager.cancel(MainActivity.mainIntent);
      MainActivity.mainIntent.cancel();
          }
        }   
</code></pre>
