简体   繁体   中英

Create Reminder Notification for Android

I know how to create scheduled notification in Android by using alarm service but what I want to do now is to create notification in more frequent way.

For example, I want to push notification for 8 hours at the interval of 20 mins. In this case, is it efficient to use alarm service or timertask will be the better choice?

No matter which method, I wish to able to cancel it in the halfway. Thanks.

Timertask starts new thread and works in it. So if your app will work in background and your app will be closed by android, you won't receive any notification. AlarmManager provides access to the system alarm services. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. ( link ). So it will start your app even if it was closed. And you have to understand how you app will work with this notifications. If it works only while user works in app, you can use timertask, but if it has to work in background(for example you will receive notification even if user doesn't work with a phone/tablet), it will be better use alarmanager. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM