Search code examples
androidandroid-studiobroadcastreceiverandroid-pendingintent

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?


Solution

  • 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