简体   繁体   中英

AlarmManager not taking more than one queue Android

I just recently started to mess with the alarm manager, and I figured out most of it, but right now its starting to be a bit annoying. So, right now I have it set up with a date and time picker, you type in the date and time and it will pop up a toast message when that times comes, but it seems like it will only take one alarm and any other ones I set get destroyed. Is this something the alarm manager does by itself, or is there something I am missing. Here is my code for my main class, the other is just a broadcast receiver with a toast message in it, so I won't post it.

public class TextScheduler extends ListActivity {
protected Toast mToast; 
TimePicker time;
DatePicker date;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(setTime);
    time = (TimePicker) this.findViewById(R.id.timePicker1);
    date = (DatePicker) this.findViewById(R.id.datePicker1);
}
private OnClickListener setTime = new OnClickListener() {
    public void onClick(View v) {
        Calendar cal = Calendar.getInstance();
        cal.set(date.getYear(), date.getMonth(), date.getDayOfMonth(), time.getCurrentHour(), time.getCurrentMinute());

        Intent intent = new Intent(TextScheduler.this, AReceiver.class);
        intent.putExtra("caldata", "hooray!!");
        PendingIntent sender = PendingIntent.getBroadcast(TextScheduler.this, 1234567, intent, 0);

        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
    }
};
    }

Let me know if you need any more info, thanks in advance!

WWaldo

AlarmManager compares PendingIntents to see if it already exits. Just change the ID (in your case 1234567 ), and it will allow you to create additional alarms: one per ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM