As far as I can tell, there are three different reasons a service was started:
I recently found myself needing to know why a service was started, so I came up with the snippet below. Hopefully it can help somebody else.
- Manually started using StartService
- Scheduled start using StartServiceAt or StartServiceAtExact
- Automatically started at boot using #StartAtBoot
I recently found myself needing to know why a service was started, so I came up with the snippet below. Hopefully it can help somebody else.
B4X:
If StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
ToastMessageShow("Started because device booted", False)
Else If Bit.And(StartingIntent.Flags, 4) = 4 Then
' https://developer.android.com/reference/android/content/Intent#FLAG_FROM_BACKGROUND
ToastMessageShow("Started from background", False)
Else
ToastMessageShow("Started manually", False)
End If