Should I use PendingIntent.getService() or getBroadcast with AlarmManager?

前端 未结 2 741
傲寒
傲寒 2020-12-13 12:30

My app needs to grab some data from the web at a specific time each day. So I use an AlarmManager to schedule the task and that works ok.

But when looking at various

2条回答
  •  一整个雨季
    2020-12-13 13:01

    One uses PendingIntent.getBroadcast() to call a broadcast receiver when the alarm goes off and inside that receiver the service to do the real work is started.

    it has one more step in starting service than

    Another approach is to use PendingIntent.getService() and call the service directly when that alarm goes off.

    then you should use the second approach as it is reducing your one step in execution..

提交回复
热议问题