开发者

What is the idea behind creating Event Reminder app in android

I want to create Event Reminder App, I search and found that I need to use a service and broadcast receiver.

But it is not clear for me what is the role of each components ?

As I understand-but I am not sure- that the App needs an Activity that when starts, it开发者_开发百科 runs the service ( which check the current time with times are stored persistently , for example in database !). when the two times match , the service create a broadcast, and our broadcast receiver receives it and create Alert.

My questions are:

  1. Does this inception is correct ?
  2. How to make the service running and always check the time ( do we need some infinite loop?!!)

thanks in advance,


Activities and Services can be killed off without notice anytime system decides it's low on resources. There is no guarantee that your Service would run all the time. Also, if phone is in sleep mode, your code stops executing.

So:

  1. The premise is wrong, for the reasons stated above.
  2. You cant guarantee that Service would be running all the time.

For your purpose you should be using AlarmManager. It is garanteed to call your code when alarm is triggered. Also important - AlarmManager survives device restarts.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜