The onReceive () broadcast receiver receives a call several times

I have a boot_compiled receiver that receives notification on boot.

<receiver android:name=".BootCompletedReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 

But it seems to be called several times. I start the timer, and then the service, which leads to several timers, and then the service gets reset and starts again.

Create a timer. This is not a repeating timer, is it ?:

  private void setAlarm(Context context, long interval) { try { AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(RespondAlarmReceiver.ACTION_RESPOND_SMS); intent.putExtra("isChecking", true); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP; long triggerAtTime = SystemClock.elapsedRealtime() + interval; //interval is 60,000 alarms.set(alarmType, triggerAtTime, alarmIntent); } catch (Exception e) { Log.e(DEBUG_TAG, "Unable to set alarm"); } 

As a side note, if anyone knows how to connect an Eclipse debugger to a broadcast receiver for downloading or to a running service, that would be fantastic.

+7
source share
1 answer

It is strange that you will run multiple timers. Try passing PendingIntent.FLAG_ONE_SHOT as the last argument inside PendingIntent.getBroadcast

+4
source

All Articles