안드로이드 개발 질문/답변
(글 수 45,052)
public class AlarmManage { //알람 관리
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent;
public void setAlarm(){
//Toast.makeText(getApplicationContext(), "알람이 설정되었습니다띠용",
// Toast.LENGTH_LONG).show();
int hour = 0;
int minute = 0;
long alarmTime = 0;
int count = 0;
DbAdapter dbAdapter; //db에서 시간정보 불러옴 ㅋ
dbAdapter = new DbAdapter(getApplicationContext());
dbAdapter.open();
Cursor cursor;
cursor =
dbAdapter.mDb.rawQuery("SELECT hour,min,content FROM plan ORDER BY hour,min ASC;", null);
startManagingCursor(cursor);
PendingIntent[] sender = new PendingIntent[cursor.getCount()]; 배열로만들어서 각각에다가 requestcode를 증 가시키면서 넣었습니다.
while(cursor.moveToNext()){
intent = new Intent(getApplicationContext(), AlarmReceiver.class);
sender[count] = PendingIntent.getBroadcast(getApplicationContext(), count, intent, 0);
배열로만들어서 각각에다가 requestcode를 증가시키면서 넣었습니다.(count부분)
hour = cursor.getInt(0);
minute = cursor.getInt(1);
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
alarmTime = cal.getTimeInMillis();
am.set(AlarmManager.RTC_WAKEUP, alarmTime, sender[count]);
count = count++;
}
}
결과는 등록된 여러개의 알람중 마지막것만 작동됩니다. 문제점좀 지적해주세요~!




해결했네요 count = count++; 이아니라 count++; 로했어야 했네요 ㅋㅋㅋㅋ