AlarmManager 不占用多个队列 Android

发布于 2024-11-10 07:44:35 字数 1362 浏览 3 评论 0原文

我最近才开始搞乱警报管理器,我已经弄清楚了其中的大部分内容,但现在它开始有点烦人了。所以,现在我已经设置了一个日期和时间选择器,你输入日期和时间,当时间到来时它会弹出一条吐司消息,但似乎它只需要一个闹钟和任何其他闹钟我设定被摧毁。这是警报管理器自己做的事情,还是我缺少什么。这是我的主类的代码,另一个只是一个带有 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);
    }
};
    }

如果您需要更多信息,请告诉我,提前致谢!

瓦尔多

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所的.畏惧 2024-11-17 07:44:36

AlarmManager 比较 PendingIntents 以查看它是否已经存在。只需更改 ID(在您的情况下为 1234567),您就可以创建其他警报:每个 ID 一个。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文