사용자가 기억해야 할 작업 목록을 작성할 수있는 todo 응용 프로그램을 만들고 있습니다. 목록에 모든 인스턴스를 만들 때 엔트리 기한에 도달하면 경보가 울리도록 설정했습니다. 알람 수신자는 마감일에 도달했음을 사용자에게 알려주는 알림을 생성합니다.android에서 여러 개의 알람을 생성하는 데 문제가 있습니다.
내가 겪고있는 문제는 알림에 의도적으로 전달하는 여분의 문자열이 제대로 업데이트되지 않는다는 것입니다. 첫 번째 경보는 잘 작동하지만 첫 번째 항목 다음에 만드는 모든 항목은 첫 번째 항목과 동일한 추가 문자열을 가져옵니다.
다음과 같이 알람을 설정하기위한 내 코드는 다음과 같습니다
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, DeadlineActivator.class);
intent.setAction("todo" + System.currentTimeMillis());
intent.putExtra("todoname", name);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
(int)System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, deadline.getTime(), pendingIntent);
는 어떤 방식으로 helpfull하지만 항목의 이름은 알람
onRecieve 방법 고유 한 경우
는 몰라 디버깅, 나는 알람에 대한 의도를 만들 때 사용하는 이름 var에 올바른 값이 있는지 볼 때이
public void onReceive(Context context, Intent intent)
{
String todoName = intent.getStringExtra(ToDoItem.TODONAME);
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent onClickIntent = new Intent(context, WatchToDo.class);
onClickIntent.putExtra(Auth.TARGET_TODO, todoName);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
String body = "Deadline of " + todoName + " has been reached";
String title = "Deadline reached";
Notification n = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true)
.build();
nm.notify(NOTIFICATION_ID, n);
}
것 같습니다. 그러나 onRecieve의 todoName var은 이전 값을 유지합니다.