IntentService won't start using AlarmManager

流过昼夜 提交于 2019-12-01 16:33:48
ρяσѕρєя K

As in documentation, PendingIntent.getBroadcast() is used to retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

You need to call PendingIntent.getService() instead, which will start IntentService:

PendingIntent pending = PendingIntent.getService(this, 0, alarmIntent, 0);

Look closely at the AlarmManager API and the PendingIntent. The AlarmManager.set() API is expecting a broadcast intent, which you are providing. However, you're trying to send a broadcast intent to a service, which cannot be done. Just create a BroadcastReceiver to catch the Intent and your BR should then start your service.

linjo wanbo

The API says:

typically comes from IntentSender.getBroadcast().

that means PendingIntent.getService can work too. I tested it, and it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!