Alarm Manager and Notification in android
Asked Answered
I

1

9

All, I have some doubt in basics .kindly help me to resolve it. in which scenario we will use Alarm manager and in which scenario we will use Notification.

Here is my understandings-Alarm-General Wakeup alarm Notification-used to notify new events...

If the above thing is correct please help me where the REMINDER will falls.

Inspissate answered 1/7, 2013 at 12:25 Comment(0)
B
20

Alarm manager is not a user notification system but an event for the phone to wake up and do something at a certain time.

Notifications are what you would use to notify the user of an event.

You can wire this all together using a BroadcastReceiver to capture the alarm manager events and start a notification.

Here's a simple example of how to do it.

Blitzkrieg answered 1/7, 2013 at 12:29 Comment(6)
Thanks CodeChimp... i cant get 3 point can u clarify it one more time.Inspissate
Point 3 is a helper class to set the alarm. So from where you want to set the alarm (say a button click on your activity) you would instantiate the class and call startAlarm Something like this (I have just hand wrote the code here so syntax may be slightly off). AlarmService as = new AlarmService(context); as.startAlarm();Blitzkrieg
It's not working for me. What am I doing wrong? AlarmReciver.startAlarm() is never being called.Restivo
Ok, I found the problem! You should register BroadCastReciver like this <receiver android:name="you.package.name.AlarmReceiver" />Restivo
How can you run it in the background? like even if the application is closed it will still fire a notification?Solidstate
If you use the alarm manager as indicated it will trigger the receiver (and notification if that's what's in the receiver) even if the app is not running.Blitzkrieg

© 2022 - 2024 — McMap. All rights reserved.