简体   繁体   中英

JobScheduler problems on Android 8

I have my application that uses JobScheduler to check is it alive or not. As far as it must work in cases:

  • User removed app from recent apps
  • Smartphone was rebooted or battery was exhausted

Anyway application should launch as soon as it is possible.

I used JobScheduler that worked perfect. But since under sdk26 Android doesn't launch my app if it was removed from recents.

What is the solution now? How can I setup JobScheduler to force it to launch my JobService ?

When you schedule your periodic job, use setPersisted(true) . This will keep the job scheduled even after a reboot. Note: Requires the RECEIVE_BOOT_COMPLETED permission. After your app is installed, your user must open it one time before the scheduled job stays persistent across reboots.

JobInfo jobInfo = new JobInfo.Builder(
                        JOB_ID, new ComponentName(context, MyJobService.class))
                        .setPeriodic(30 * 60 * 1000)
                        .setPersisted(true)
                        .setRequiresBatteryNotLow(true)
                        .build(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM