2017-10-12 3 views
0

알람 신호가 있습니다. 경보를 두 번 이상 발동시키는 방법 및 각 경보에서? 하나의 알람 시계 만 작동하고 나머지는 덮어 씁니다.TaskReminer는 하나의 알람 만 작동합니다.

코드 :

public class ReminderManager { 

private Context mContext; 
private AlarmManager mAlarmManager; 

public ReminderManager(Context context) { 
    mContext = context; 
    mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
} 

public void setReminder(Long taskId, Calendar when) { 

    if (when.getTimeInMillis() < System.currentTimeMillis()) { 
     return; 
    } 

    Intent i = new Intent(mContext, OnAlarmReceiver.class); 
    i.putExtra(DbAdapter.KEY_ROWID, (long)taskId); 
    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT); 
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), pi); 
} 

} 

나는 문제가 requestCode가에 있음을 이해하지만, 나는 그것을 해결하는 방법을 이해할 수 없다 ..

답변

0
PendingIntent pi = PendingIntent.getBroadcast(mContext,{unique id}, i, PendingIntent.FLAG_ONE_SHOT); 

다음은 각중인 의도가 제공 될 것입니다 유일한 ID. 임의의 ID를 생성하고이 ID를 고유 한 ID로 보류중인 의도에 할당합니다. 그렇지 않으면 대기 의도는 임의의 숫자

Random rand = new Random(); 
int n = rand.nextInt(); 

는 고유 ID를 들어

을 만들 덮어 또는 어떤 경우 데이터베이스에서 ID를 사용합니다.

+0

이해합니다. 어떻게 해결할 수 있습니까? –

+0

임의의 정수 생성 ... –

+0

임의의 rand = 새로운 임의(); int n = rand.nextInt(); –