Android Code Snippet How to determine what started a Service

Discussion in 'Code Snippets' started by Sandman, Jul 24, 2018.

  1. Sandman

    Sandman Well-Known Member Licensed User

    As far as I can tell, there are three different reasons a service was started:
    1. Manually started using StartService
    2. Scheduled start using StartServiceAt or StartServiceAtExact
    3. 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.

    If StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
    ToastMessageShow("Started because device booted"False)
    Else If Bit.And(StartingIntent.Flags, 4) = 4 Then
        ToastMessageShow("Started from background"False)
    ToastMessageShow("Started manually"False)
    End If
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice