【发布时间】:2011-09-20 01:23:17
【问题描述】:
我有一个 boot_completed 接收器,它会在启动时收到通知。
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
但它似乎被多次调用。我启动了一个计时器,然后启动了一个服务,这导致了多个计时器,然后该服务被重置并再次运行。
像这样创建计时器。这不是一个重复计时器,是吗?:
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");
}
附带说明一下,如果有人知道如何将 Eclipse 调试器连接到启动广播接收器或正在运行的服务,那将是非常棒的。
【问题讨论】:
-
你有没有机会解决这个问题?
标签: android eclipse broadcastreceiver