PendingIntent 获取请求代码 [英] PendingIntent get requestCode
问题描述
我使用 AlarmManager
来启动服务.当我设置 AlarmManager
时,我使用 PendingIntent
并使用一个唯一的 requestCode,它等于我数据库中的 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?我基本上只需要 requestCode 参数.我想使用该 ID 从我的数据库中检索数据并将其显示在通知中.我已经实现了所有的东西,我只需要那个 requestCode.能拿到吗?
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
的 extras 中.根据 Javadoc requestCode 甚至还没有使用.
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 获取请求代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!