I have a boot_completed receiver which gets notified on boot.
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
But it appears to get called multiple times. I start a timer, and then a service, which leads to multiple timers, and then the service gets reset and runs again.
Creating timer like this. 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 anybody knows how to attach the Eclipse debugger to the Boot-up broadcast receiver or to a running service, that would be fantastic.
Retrieve the current result extra data, as set by the previous receiver. This can be called by an application in onReceive(Context, Intent) to allow it to keep the broadcast active after returning from that function.
Because a receiver's onReceive(Context, Intent) method runs on the main thread, it should execute and return quickly. If you need to perform long running work, be careful about spawning threads or starting background services because the system can kill the entire process after onReceive() returns.
A broadcast receiver (receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.
A Service receives intents that were sent specifically to your application, just like an Activity. A Broadcast Receiver receives intents that were broadcast system-wide to all apps installed on the device.
It's strange that you'd be getting multiple timers started. Try passing PendingIntent.FLAG_ONE_SHOT
as the last argument inside of PendingIntent.getBroadcast
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With