CodexBloom - Programming Q&A Platform

implementing Android JobScheduler Not Resuming After Device Reboot on Android 14

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-19
android jobscheduler workmanager Kotlin

Does anyone know how to I'm building a feature where I'm working with a question with the `JobScheduler` in my Android app where scheduled jobs are not resuming after the device reboots on Android 14. I have set up a simple job that should run daily to sync data with a server. I am using the `WorkManager` library for this, but it seems the scheduled jobs are not triggering after a reboot, even though I've set the appropriate flags. I've implemented the following code to schedule the job: ```kotlin val jobScheduler = getSystemService(JobScheduler::class.java) val jobInfo = JobInfo.Builder(JOB_ID, ComponentName(this, SyncJobService::class.java)) .setRequiredNetworkType(NetworkType.CONNECTED) .setPeriodic(TimeUnit.DAYS.toMillis(1)) .setPersisted(true) .build() jobScheduler.schedule(jobInfo) ``` I also added the following permission to my `AndroidManifest.xml`: ```xml <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> ``` Additionally, I have set up a `BroadcastReceiver` to reschedule the job after reboot: ```kotlin class BootReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent?.action == Intent.ACTION_BOOT_COMPLETED) { // Reschedule job here } } } ``` However, the `onReceive` method is not being triggered after the device restarts. I've verified that the receiver is registered in the manifest like this: ```xml <receiver android:name=".BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> ``` I have checked the logs, and I don't see any errors, but the job doesn't seem to resume after reboot. I tried testing on both an emulator and a physical device running Android 14. Is there something I might have missed or a requirement that changed in this version regarding `JobScheduler` and boot completion? This is my first time working with Kotlin latest. Any pointers in the right direction? I'm using Kotlin 3.10 in this project.