Hi there, I have some problems when I try to setup an alarm. I am using the AlarmManager to set an alarm. This alarm is picked up by my Receiver that creates a notification.
My first problem: When I setup two alarms, my notification thats init by the alarm event always shows me the first input parameter. Whats going wrong? My second problem: I read that I should use an id for the notification to cancel it, when its submitted. What is the best way to create different ids? I just used javas math. Although the ids are not equals in my tests, it is not really a good solution. Any ideas? Here is my code. Although the titleString is not the same like in the first init (my Log entry in initializeAlarm() shows that the first input not equals a second input) the onReceive method tells me that todoTitle is always the same. private void initializeAlarm(String titleString, String alarmString){ if(alarmString != null && alarmString.length() == 16){ Intent intent = new Intent(this, AlarmReceiver.class); intent.putExtra("todoTitle", titleString); PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date date = new Date(); try { date = sdf.parse(alarmString); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(date); // Schedule the alarm! AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); Log.v("test",intent.getStringExtra("todoTitle")); } } public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { int notification_id = (int)(Math.random()*100*Math.random()*100); final Bundle extras = intent.getExtras(); String tickerText = extras.getString("todoTitle"); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, "Todo News", System.currentTimeMillis()); Intent activityIntent = new Intent(context, ToDosActivity.class); activityIntent.putExtra("notificationId", notification_id); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent startIntent = PendingIntent.getActivity(context, 0, activityIntent, 0); notification.setLatestEventInfo(context, "Todo ansehen", tickerText, startIntent); notification.vibrate = new long[]{100,250}; mNotificationManager.notify(notification_id, notification); } } Thanks for any ideas! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en