私はアラームのリストを持っています。最初のものを入れ、アラームが鳴ったら次のものを入れます....これはうまくいきます。ただし、アプリケーションが十分な時間バックグラウンドにある場合、アラームは機能しません。
マニフェストに入れました:
<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);
}
}
問題はどこだ?問題は受信側の動作だと思いますが、解決方法がわかりません。多くのリソースが消費されるため、サービスを常にリッスンすることはお勧めできません。
私の英語でごめんなさい、ありがとう!