Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Pending Intent request code be negative?

I have searched all over internet but not found much help there. I am making an alarm application in which i am using pending intents with alarm manager. I want to set two alarms based on specific id of the sqlite database table. For the first alarm I am setting pending intent request code as positive id, and for the second intent I am setting pending intent request code as negative id (-1 * id). Here is the code

PendingIntent pi = PendingIntent.getBroadcast(context, _id, i, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent pi = PendingIntent.getBroadcast(context, -1 *_id, i, PendingIntent.FLAG_UPDATE_CURRENT);

Can _id be negative?

like image 358
Ali Mehdi Avatar asked Oct 22 '25 02:10

Ali Mehdi


1 Answers

usually _id is marked as autoincrement. Accordingly to the sqlite documentation, for autoincrement, if you don't insert explicitly a negative value, then the values generated for this column are always positive. _id could be negative if you explicitly insert a negative value.

Can Pending Intent request code be negative?

the documentation says nothing about negative values. The method accepts an int value and, in java, all the primitive types are signed. So, we have to assume that the request code can assume negative values

like image 148
Blackbelt Avatar answered Oct 23 '25 16:10

Blackbelt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!