0

私はアラームのリストを持っています。最初のものを入れ、アラームが鳴ったら次のものを入れます....これはうまくいきます。ただし、アプリケーションが十分な時間バックグラウンドにある場合、アラームは機能しません。

マニフェストに入れました:

<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);
    }
}

問題はどこだ?問題は受信側の動作だと思いますが、解決方法がわかりません。多くのリソースが消費されるため、サービスを常にリッスンすることはお勧めできません。

私の英語でごめんなさい、ありがとう!

4

2 に答える 2

0

アクティビティが十分に長くバックグラウンドにある場合、システムによって強制終了された可能性があります。Service と setForeground() を使用して、目標を達成することができます。

于 2013-07-24T10:33:08.967 に答える
0

次のアラームの設定はどうしていますか?サービス経由で行う場合は、ウェイクロックを取得する必要があります。

電話がスリープ状態にあり、アラームを受信した場合、電話は BroadcastReceiver が onReceive() メソッドにある間のみ起動し、その後再びスリープ状態になります。したがって、「setNextAlarm」が呼び出されるという保証はありません。

于 2013-07-24T11:10:36.310 に答える