I want my app to start at 9am everyday. for that I start Alarm_1 using setRepeatingAlarm()
that starts at 9am everyday.
manager.setRepeating(AlarmManager.RTC_WAKEUP,
timeOn.getTimeInMillis(), 86400000,startingIntent);
From alarm_1, I start another alarm, MainAlarm, that repeatedly starts my service at the interval of 1min.
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), duration, MainActivity.mainIntent);
I want my app to stop at 9pm everyday.
For that I start Alarm_2 using setRepeatingAlarm()
that cancel()
MainAlarm everyday at 9pm.
But this is not working as expected.
What should be done? Is there any problem because I am using 3 alarms?
The alarms do not work the next day.
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();
}
}