问题
i have a background Service which starts and AlaramManager. i've logged when the AlarmManager fires and see that it only fires when the application has no activities running and the only thing that runs is the background Service.. why is that ?
@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);
}
来源:https://stackoverflow.com/questions/13664523/alarmmanager-from-service