的PendingIntent get请求code [英] PendingIntent get requestCode

查看:323
本文介绍了的PendingIntent get请求code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AlarmManager 来启动服务。当我设置了 AlarmManager 我用的PendingIntent 并使用独特的请求code等于一个ID行中我的数据库。

I use an AlarmManager to start a service. When i set up the AlarmManager i use the PendingIntent and use a unique requestCode which is equal to a id row in my database.

PendingIntent pendingIntent = PendingIntent.getBroadcast(SettingsActivity.this,
                            lecture.getId(), myIntent, 0); 

我怎样才能找回我的服务,该ID在启动时?我基本上只需要请求code参数。我想使用该ID从我的数据库中检索数据并显示在一个通知。我已经实现了所有的东西,我只需要这一请求code。是否有可能得到它?

How can I retrieve that id in my service when it starts? I basically need only the requestCode parameter. I want to use that id to retrieve data from my database and show it in a notification. I have implemented all the stuff, I just need that requestCode. Is it possible to get it?

感谢

推荐答案

您需要把 lecture.getId() myIntent的临时演员。据的Javadoc <一个href=\"http://developer.android.com/reference/android/app/PendingIntent.html#getBroadcast%28android.content.Context,%20int,%20android.content.Intent,%20int%29\">request$c$c甚至没有用呢。

You need to put lecture.getId() into extras of your myIntent. According to Javadoc requestCode is not even used yet.

// store id
myIntent.putExtra("id", lecture.getId());

// read id or -1, if there is no such extra in intent
int id = myIntent.getIntExtra("id", -1);

这篇关于的PendingIntent get请求code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆