IntentService won't start using AlarmManager

前端 未结 3 415
野趣味
野趣味 2021-01-17 15:09

I know there is a lot of questions about this but I really don\'t know where is my mistake.

My service is registered in the AndroidManifest.xml file

         


        
相关标签:
3条回答
  • 2021-01-17 16:08

    The API says:

    typically comes from IntentSender.getBroadcast().

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

    0 讨论(0)
  • 2021-01-17 16:10

    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.

    0 讨论(0)
  • 2021-01-17 16:11

    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);
    
    0 讨论(0)
提交回复
热议问题