Fix crash when encountering null PendingIntent.

This commit is contained in:
Cody Henthorne 2021-08-02 13:14:55 -04:00 committed by Greyson Parrelli
parent 4a52532256
commit 065a39992a
2 changed files with 11 additions and 5 deletions

View file

@ -256,9 +256,11 @@ class MessageNotifierV2(context: Application) : MessageNotifier {
lastScheduledReminder = 0
threadReminders.clear()
val pendingIntent: PendingIntent = PendingIntent.getBroadcast(context, 0, Intent(context, ReminderReceiver::class.java), PendingIntent.FLAG_CANCEL_CURRENT)
val alarmManager: AlarmManager? = ContextCompat.getSystemService(context, AlarmManager::class.java)
alarmManager?.cancel(pendingIntent)
val pendingIntent: PendingIntent? = PendingIntent.getBroadcast(context, 0, Intent(context, ReminderReceiver::class.java), PendingIntent.FLAG_CANCEL_CURRENT)
if (pendingIntent != null) {
val alarmManager: AlarmManager? = ContextCompat.getSystemService(context, AlarmManager::class.java)
alarmManager?.cancel(pendingIntent)
}
}
companion object {

View file

@ -31,7 +31,11 @@ public abstract class PersistentAlarmManagerListener extends BroadcastReceiver {
Log.i(TAG, getClass() + " scheduling for: " + scheduledTime + " action: " + intent.getAction());
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
if (pendingIntent != null) {
alarmManager.cancel(pendingIntent);
alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
} else {
Log.i(TAG, "PendingIntent somehow null, skipping");
}
}
}