以初始值启动服务

发布于 2024-10-16 06:15:01 字数 720 浏览 3 评论 0原文

我正在尝试在我的笔记/待办事项应用程序中使用提醒/警报服务。我可以为特定项目设置提醒,并且警报会成功触发并显示通知。

我的问题是我的 Service 如何知道哪个笔记/待办事项设置了该特定提醒。我希望用户能够单击状态栏中的通知并显示触发它的项目。但我无法将该信息传递给 Service,因为它们不接受来自 PendingIntentBundles

我目前使用以下内容设置警报:

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 技术交流群。

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

发布评论

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

评论(1

番薯 2024-10-23 06:15:01

为什么不将所有需求放入 Intent 数据中呢?像这样的事情:

    final Intent intent = new Intent(context, UpdatesActivity.class);
    intent.putExtra(ID, "foo");
    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

然后在接收端你做

    String id = getIntent().getStringExtra(ID);

Why don't you put all your need into Intent data? Something like this:

    final Intent intent = new Intent(context, UpdatesActivity.class);
    intent.putExtra(ID, "foo");
    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

Then on receiving end you do

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