Skip to content Skip to sidebar Skip to footer

Android Alarm Not Cancelling

I am in the main activity. There is a Login button bLogin. When it is pressed, a Logout button is displayed bLogout. The onClick methods for the two buttons are as follows: bLogin.

Solution 1:

Don't know what's wrong with your code, but if you want to cancel the pending intent you can use

PendingIntent.getBroadcast(getActivity(), 327, pendingIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT).cancel();

to cancel the pending intent. I think it'll do the same think as cancelling your AlarmManager. Although you might need to change the way you check the way your alarm is set.

Hope this helps.

Solution 2:

You aren't cancelling the PendingIntent. When you call

manager.cancel(pendingIntent) 

you are cancelling the alarm. This doesn't cancel the PendingIntent. The PendingIntent still exists. So when you then call

boolean alarmUp = (PendingIntent.getBroadcast(getApplicationContext(), 327,
        new Intent(getApplicationContext(), AlarmReceiver.class),
        PendingIntent.FLAG_NO_CREATE) != null);

the PendingIntent still exists, so PendingIntent.getBroadcast() will return a non-null. result. alarmUp will always be true.

You need to cancel the PendingIntent after you cancel the alarm, like this:

pendingIntent.cancel();

Post a Comment for "Android Alarm Not Cancelling"