以初始值启动服务
我正在尝试在我的笔记/待办事项应用程序中使用提醒/警报服务。我可以为特定项目设置提醒,并且警报会成功触发并显示通知。
我的问题是我的 Service
如何知道哪个笔记/待办事项设置了该特定提醒。我希望用户能够单击状态栏中的通知并显示触发它的项目。但我无法将该信息传递给 Service
,因为它们不接受来自 PendingIntent
的 Bundles
。
我目前使用以下内容设置警报:
private void createAlarm() {
Intent i = new Intent(this, AlarmService.class);
PendingIntent sender = PendingIntent.getService(this, 0, i, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, mReminderCal.getTimeInMillis(), sender);
}
我只需要一种方法来发送数据库中项目的 _id
,以便我的服务可以使用相同的 _id
启动该项目单击通知时。
我希望我的问题不会太令人困惑。
谢谢!
I am trying to get a reminder/alarm Service` working in my note/todo app. I am able to set a reminder for a particular item and the alarm triggers and displays a notification successfully.
My problem is how can my Service
know which note/todo item set that particular reminder. I'd like for the user to be able to click on the notificaiton in the status bar and have the item which trigger it come up. But I have no way of passing that information to the Service
as they don't accept Bundles
from the PendingIntent
.
I currently set the alarm with the following:
private void createAlarm() {
Intent i = new Intent(this, AlarmService.class);
PendingIntent sender = PendingIntent.getService(this, 0, i, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, mReminderCal.getTimeInMillis(), sender);
}
I just need a way to send along the _id
of the item in my database so my Service can launch the item with that same _id
when the notification is clicked.
I hope my question isn't too confusing.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不将所有需求放入 Intent 数据中呢?像这样的事情:
然后在接收端你做
Why don't you put all your need into Intent data? Something like this:
Then on receiving end you do