Multiple alarms at the same time in Android

后端 未结 1 581
小蘑菇
小蘑菇 2021-01-24 02:16

I\'m stuck on this problem. I\'ve read many solutions on stack overflow but none of these have solved my problem.

Here\'s my code: In my Main Activity, I wrote this--

1条回答
  •  有刺的猬
    2021-01-24 03:10

    if (alarmRun == false){
              PendingIntent pending = PendingIntent.getBroadcast(this.context, 0, alarm, 0);
              AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                        alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 15000, pending);
                }
    

    Calling setRepeating will cause the BroadcastReceiver to be triggered multiple times at an interval of 15000 milliseconds. Use setExact instead.

    0 讨论(0)
提交回复
热议问题