fix cancel() called with a null PendingIntent

In case no connection can be established, AlarmPingSender stop method will be called when it has not been started yet. `java.lang.NullPointerException: cancel() called with a null PendingIntent` will be thrown as the pending intent has not been setup yet.
This commit is contained in:
Alexander Rust 2016-08-02 07:49:05 +02:00 committed by GitHub
parent 7459017f3e
commit adffd9391c

View File

@ -81,13 +81,13 @@ class AlarmPingSender implements MqttPingSender {
@Override
public void stop() {
// Cancel Alarm.
AlarmManager alarmManager = (AlarmManager) service
.getSystemService(Service.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
Log.d(TAG, "Unregister alarmreceiver to MqttService"+comms.getClient().getClientId());
if(hasStarted){
// Cancel Alarm.
AlarmManager alarmManager = (AlarmManager) service.getSystemService(Service.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
hasStarted = false;
try{
service.unregisterReceiver(alarmReceiver);