0

9:00と21:00に2つのAlarmManagerがありますが、2番目のアラームのみを実行します。

    ////////9:00am/////////
    Intent aviso = new Intent(FijarAlerta.this,Servicio.class);
    PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 0, aviso, PendingIntent.FLAG_UPDATE_CURRENT);
           //set the hour
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 9);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);

2番目のアラーム

////////21:00pm//////////
    Intent avisopm = new Intent(FijarAlerta.this,Servicio.class);
    PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
                 //set the hour
    Calendar calpm = Calendar.getInstance();
    calpm.set(Calendar.HOUR_OF_DAY, 21);
    calpm.set(Calendar.MINUTE, 0);
    calpm.set(Calendar.SECOND, 0);
    AlarmManager ampm = (AlarmManager)getSystemService(ALARM_SERVICE);
    ampm.setRepeating(AlarmManager.RTC_WAKEUP,calpm.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pipm);
4

2 に答える 2

1

への呼び出しの 2 番目のパラメーターは、PendingIntent.getService()ケースごとに異なる数値にする必要があります。例えば:

PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 111, aviso,       PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 222, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

現時点では、2 番目の pendingIntent は最初のものを上書きするだけです

于 2013-01-28T10:53:36.900 に答える
0

2 番目のアラーム ラインを置き換えるだけです。

PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

1つ下で

PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 1, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

さて、成功しない場合はコメントさせてください。

コーディングをお楽しみください。:)

于 2013-01-28T11:22:37.190 に答える