开发者

Help with cancelling alarms [duplicate]

开发者 https://www.devze.com 2023-03-01 01:53 出处:网络
This question already has answers here: canceling Alarm in alarm manager? (2 answers) Closed 9 years ago.
This question already has answers here: canceling Alarm in alarm manager? (2 answers) Closed 9 years ago.

When user sets alarm and when i want to cancel alarm using a button i have a problem. If the user sets the alarm and then without leaving the app presses the butt开发者_开发百科on to cancel it it cancels fine. but if the user leaves the app and comes back and clicks the button cancel the alarm it wont work and it fires an error message.


SilentManager.mAlarmManager.cancel(SilentManager.pi); is the thing that keeps crashing if you leave the app and come back.

Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your "crash". Most likely, you will find that it is a NullPointerException, because your process has been terminated and therefore your static pi data member is null.

If this is your error, the solution is:

Step #1: Get rid of the pi static data member.

Step #2: When you cancel(), create a PendingIntent on an equivalent Intent to the one you used to create the alarm in the first place.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号