Skip to content

Commit

Permalink
dont run task when trigger was deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Apr 25, 2024
1 parent 5f9d31b commit 829c782
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ private PendingIntent getIntent(long triggerId){
i.putExtra(TRIGGER_ID, triggerId);

// Todo: Beacause of the long to int cast, this may fail when the user has more than Integer.MAX tasks.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return PendingIntent.getBroadcast(context, (int) triggerId, i, PendingIntent.FLAG_UPDATE_CURRENT ^ PendingIntent.FLAG_IMMUTABLE);
} else {
return PendingIntent.getBroadcast(context, (int) triggerId, i, PendingIntent.FLAG_UPDATE_CURRENT);
}
return PendingIntent.getBroadcast(context, (int) triggerId, i, PendingIntent.FLAG_UPDATE_CURRENT ^ PendingIntent.FLAG_IMMUTABLE);
}

@Override
Expand All @@ -181,7 +177,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
this.dbHandler = new DatabaseHandler(getBaseContext());
this.context = getBaseContext();
Trigger t = dbHandler.getTrigger(id);
//Todo: Handle case when t is not defined because the trigger was deleted but scheduled

// this can happen if the trigger was scheduled, but then deleted.
if(t == null) {
stopForeground(true);
return Service.START_NOT_STICKY;
}

startTask(t);
queueSingleTrigger(t);
stopForeground(true);
Expand Down

0 comments on commit 829c782

Please sign in to comment.