简体   繁体   English

AlarmManager 不占用多个队列 Android

[英]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.所以,现在我已经为它设置了一个日期和时间选择器,你输入日期和时间,到时候它会弹出一条 toast 消息,但它似乎只需要一个警报和任何其他警报我设置被摧毁。 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.这是我的主要 class 的代码,另一个只是一个带有 toast 消息的广播接收器,所以我不会发布它。

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. AlarmManager 比较 PendingIntents 以查看它是否已经退出。 Just change the ID (in your case 1234567 ), and it will allow you to create additional alarms: one per ID.只需更改 ID(在您的情况下为1234567 ),它将允许您创建其他警报:每个 ID 一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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