AlarmManager应每1分钟重复一次,但每1,2,3或4分钟重复一次。
因为应用程序我抛出AlarmManager
public class PacienteApp extends Application {
@Override
public void onCreate() {
AlarmManager gps = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(this, GpsReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, i, 0);
gps.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 60, pending);
}
}
由于BroadcastReceiver调用IntentService。
public class GpsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent gps = new Intent(context, GpsIntentService.class);
context.startService(gps);
}
}
并且intentservice执行任务
public class GpsIntentService extends IntentService {
public GpsIntentService() {
super("GpsIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
System.out.println("Intent service ejecutado");
}
}
由于这种情况发生在后台,我在前台运行了几个活动。
答案 0 :(得分:2)
从KitKat(API 19)开始,警报不完整,并通过最小化设备唤醒所需的次数来分批处理以延长电池寿命。
来自setRepeating()
的{{1}}:
注意:从API 19开始,所有重复警报都不准确。如果您的应用程序需要精确的交付时间,那么它必须使用一次性精确警报,每次重新安排如上所述。
targetSdkVersion
早于API 19的旧版应用程序将继续将所有警报(包括重复警报)视为完全警报。
为了获得更高的精确度,您需要使用the AlarmManager documentation并在每次警报唤醒您的应用时重新安排闹钟。但是要非常小心,因为设置频繁的警报(例如每1分钟一次)会大大减少用户的注意力。电池寿命。
来自setExact()
文件:
注意:只有对确切时间交付有强烈需求的警报(例如在请求的时间响铃的闹钟)才应准确安排。强烈建议不要使用精确报警,因为它们会降低操作系统最大限度地减少电池使用的能力。