AlarmManager from service

南笙酒味 提交于 2020-01-25 16:50:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!