我有一个后台服务启动和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);
}