我有一个报警列表,我把第一个,当它听起来我把下一个的报警.... 这是作品。 但是如果应用程序在后台有足够的时间,警报不起作用。AlarmManager在后台
我把清单:
<receiver android:name=".Alertas_Broadcast" >
<intent-filter>
<action android:name="com.pack.pack.Alertas" />
<category android:name="com.pack.pack" />
</intent-filter>
</receiver>
和广播和把新的报警功能:
public class Alertas_Broadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String mensaje = "";
if (extras != null)
mensaje = extras.getString("mensaje");
if (!mensaje.equals("")){
Utilidades.generateNotification(context, mensaje, Main.class, null);
// I put the next alarm calling setNextAlarm with the new parameters
}
}
}
public void setNextAlarm (long milisegundos, String mensaje){
Bundle extras = new Bundle();
extras.putString("mensaje", mensaje);
Intent i = new Intent("com.pack.pack.Alertas");
i.putExtras(extras);
PendingIntent pintent = PendingIntent.getBroadcast(InfoApp.miContexto, (int) milisegundos, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE);
if (milisegundos != 0){
alarm.setRepeating(AlarmManager.RTC_WAKEUP, milisegundos, 99999999, pintent);
}
else{
alarm.cancel(pintent);
}
}
问题出在哪里?我想象的问题是接收器的行为,但我不知道如何解决它。 我读过这样的说法,因为有很多资源都花费在服务器上,所以不是一个好主意。
对不起,我的英语,谢谢!
我搜索数据库中的下一个日期,并用新参数调用setNextAlarm。我也有清单中的WAKE_LOCK权限,但我没有任何服务 – user1852854