I have a class to turn on the AlarmManager
. I want to call my startMonitoring
only when the AlarmManager
does not start. The below functions are to start and stop the AlarmManager
, but they do not have functions to checking the AlarmManager
is starting/stopping (statement). How can I make a function check it?
public static class MonitorBR extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive : MonitorBR");
if (ServiceUtil.isRunningService(context, ReadService.class) == false) {
context.startService(new Intent(context, ReadService.class));
}
}
}
public void setInterval(long interval) {
this.interval = interval;
}
public void startMonitoring(Context context) {
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
intent = new Intent(context, MonitorBR.class);
sender = PendingIntent.getBroadcast(context, 0, intent, 0);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), interval, sender);
public void stopMonitoring(Context context) {
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
intent = new Intent(context, MonitorBR.class);
sender = PendingIntent.getBroadcast(context, 0, intent, 0);
am.cancel(sender);
am = null;
sender = null;
}