I am sending a request code through this to an alarm manager
Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId, broadcast_intent, PendingIntent.FLAG_UPDATE_CURRENT);
I was wondering, that in the broadcastreceiver, how can I retreive the requestcode (rowId) that I used to setup pendingIntent?
Thanks
Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId,
broadcast_intent,PendingIntent.FLAG_UPDATE_CURRENT
);
Best would be to pass the extras while referring broadcast_intent within getBroadcast() - broadcast_intent.putExtras("REQUESTCODE",rowId) ;
as follows :
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId,
broadcast_intent.putExtras("REQUESTCODE",rowId),
PendingIntent.FLAG_UPDATE_CURRENT);
The requestCode used when creating a pendingIntent is not intended to pass on to the receiver, it is intended as a way for the app creating the pendingIntent to be able to manage multiple pendingIntents.
Suppose an alarm app needed to create several pendingIntents, and later needs to cancel or modify one of them. The requestCode is used to identify which one to cancel/modify.
To pass data on, use the putExtra as described above. Note you might very well want to use RowId for both the requestCode and the Extra data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With