我有一个后台服务启动和 AlaramManager。我已经记录了 AlarmManager 何时触发并看到它仅在应用程序没有运行活动并且唯一运行的是后台服务时触发。为什么会这样?
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (app.isApplicationInitilized())
{
//stopAlarmManager();
server.start();
startAlarmManager();
}
return START_NOT_STICKY;
}
public void startAlarmManager()
{
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10*1000), 10*1000, alarmPendingIntent);
}
private void setAlarmManager() {
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, AlarmManagerReceiver.class);
alarmPendingIntent = PendingIntent.getBroadcast(this, 8258, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}