PendingIntent get requestCode

你说的曾经没有我的故事 提交于 2019-12-19 16:54:54

问题


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); 

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?

Thanks


回答1:


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);


来源:https://stackoverflow.com/questions/18378200/pendingintent-get-requestcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!