开发者

How to create asynchronous notifications in android

What is the bes开发者_运维知识库t practice to create a scheduled notification at some point in the future?

I have found a way using a Service that is triggered with a PendingIntent via the AlarmManager. In the onCreate() method of the Service I create the notification. This seems a bit like abusing the service to do something it is not supposed to be doing.

Is there another less cumbersome / more elegant method of achieving the same end? (The use case in question is giving the user a daily reminder to do something with my app)


What is the best practice to create a scheduled notification at some point in the future?

AlarmManager.

This seems a bit like abusing the service to do something it is not supposed to be doing.

Ummm...why?

Is there another less cumbersome / more elegant method of achieving the same end?

Setting an alarm requires a total of 3 to 4 Java statements, plus one for any extra you package into the Intent. Processing the alarm in a BroadcastReceiver to go raise a Notification regarding the "daily reminder" should be another ~20 lines of code, plus one entry in the manifest.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜