AlarmManager, BroadcastReceiver and Service not working

前端 未结 3 1241
时光取名叫无心
时光取名叫无心 2021-01-04 05:45

I\'m refactoring some code so that my app will pull data from a website once a day at a given time. From my research, it seems like AlarmManager is the most app

3条回答
  •  一个人的身影
    2021-01-04 06:28

    You could get AlarmManager to run the Service straight away rather than going through a BroadcastReceiver, if you change your intent like this:

    //Change the intent
    Intent downloader = new Intent(context, MyService.class);
        downloader.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
    //Change to getService()
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
    

    This may solve your problem!

提交回复
热议问题