Alarm Pending Alarm doesn't cancel

前端 未结 3 507
予麋鹿
予麋鹿 2021-01-18 16:40

I\'ve read through many questions and answers on Stackoverflow, and many of which just emphasize on the .cancel() and the special unique ID. However, now matter

3条回答
  •  广开言路
    2021-01-18 17:24

    Well for cancelling Alarm you have to create the same PendingIntent that you created while starting it. You are doing while starting,

    Intent intent = new Intent(pickTime.this, timesUp.class);
    PendingIntent timesUpIntent = PendingIntent
                                    .getService(pickTime.this, RQS_1, intent, 0);
    

    You are doing while cancelling,

    Intent intent = new Intent(this, pickTime.class);
    PendingIntent timesUpIntent = PendingIntent
                                            .getBroadcast(this, RQS_1, intent, 0);
    

    Are they same?

    No, they are not same. You are creating PendingIntent for Service to start and trying to cancel with different PendingIntent of BroadCast.

提交回复
热议问题