KBootReceiver
BroadcastReceiver that runs registered BootTasks on device boot.
Declare in AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name="dev.kindling.android.natif.KBootReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>Content copied to clipboard
Register tasks in your Application.onCreate before boot fires — i.e. always register on every app start, not just the first time:
// Application.onCreate
BackgroundHelper.addBootTask(
BootTask(
taskKey = "weekly-report",
rescheduleScheduled = BackgroundMode.WorkManagerScheduled(
uniqueName = "weekly-report",
dayOfWeek = DayOfWeek.FRIDAY,
hour = 19
)
)
)
// Or a simple one-shot on boot:
BackgroundHelper.addBootTask(
BootTask(
taskKey = "sync-on-boot",
mode = BackgroundMode.WorkManagerOnce(uniqueName = "sync-on-boot")
)
)Content copied to clipboard
Note: LOCKED_BOOT_COMPLETED fires even before the user unlocks — only use it for tasks that don't need credential-encrypted storage.