Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PendingIntent get requestCode

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

like image 813
Aksiom Avatar asked Aug 22 '13 10:08

Aksiom


People also ask

What is requestCode in PendingIntent?

requestCode is used to retrieve the same pending intent instance later on (for cancelling, etc).

Why would you use a PendingIntent?

Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.

What is PendingIntent Flag_one_shot?

FLAG_ONE_SHOT : Only allows the PendingIntent to be sent once (via PendingIntent.


1 Answers

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);
like image 74
sergej shafarenka Avatar answered Sep 21 '22 13:09

sergej shafarenka