Class ShadowService

java.lang.Object
org.robolectric.shadows.ShadowContextWrapper
org.robolectric.shadows.ShadowService
Direct Known Subclasses:
ShadowAccessibilityService, ShadowInCallService, ShadowIntentService, ShadowJobService, ShadowNotificationListenerService, ShadowQuickAccessWalletService, ShadowVoiceInteractionService, ShadowVpnService

@Implements(android.app.Service.class) public class ShadowService extends ShadowContextWrapper
  • Constructor Details

    • ShadowService

      public ShadowService()
  • Method Details

    • onDestroy

      @Implementation protected void onDestroy()
    • stopSelf

      @Implementation protected void stopSelf()
    • stopSelf

      @Implementation protected void stopSelf(int id)
    • stopSelfResult

      @Implementation protected boolean stopSelfResult(int id)
    • startForeground

      @Implementation protected void startForeground(int id, Notification notification) throws Exception
      Throws:
      Exception
    • startForeground

      @Implementation(minSdk=29) protected void startForeground(int id, Notification notification, int foregroundServiceType) throws Exception
      Throws:
      Exception
    • stopForeground

      @Implementation protected void stopForeground(boolean removeNotification)
    • getForegroundServiceType

      @Implementation(minSdk=29) protected int getForegroundServiceType()
    • stopForeground

      @Implementation(minSdk=24) protected void stopForeground(int flags)
    • getLastForegroundNotificationId

      public int getLastForegroundNotificationId()
    • getLastForegroundNotification

      public Notification getLastForegroundNotification()
    • isLastForegroundNotificationAttached

      public boolean isLastForegroundNotificationAttached()
      Returns whether the last foreground notification is still "attached" to the service, meaning it will be removed when the service is destroyed.
    • isStoppedBySelf

      public boolean isStoppedBySelf()
      Returns:
      Is this service stopped by self.
    • isForegroundStopped

      public boolean isForegroundStopped()
    • getNotificationShouldRemoved

      public boolean getNotificationShouldRemoved()
    • getStopSelfId

      public int getStopSelfId()
      Returns id passed to stopSelf(int) method. Make sure to check result of isStoppedBySelf() first.
    • getStopSelfResultId

      public int getStopSelfResultId()
      Returns id passed to stopSelfResult(int) method. Make sure to check result of isStoppedBySelf() first.
    • setThrowInStartForeground

      public void setThrowInStartForeground(Exception e)
      Configures the ShadowService so that calls to startForeground() will throw the given Exception. It can throw: ForegroundServiceStartNotAllowedException: https://developer.android.com/reference/android/app/ForegroundServiceStartNotAllowedException Or InvalidForegroundServiceTypeException: https://developer.android.com/reference/android/app/InvalidForegroundServiceTypeException Or MissingForegroundServiceTypeException: https://developer.android.com/reference/android/app/MissingForegroundServiceTypeException Or SecurityException: https://developer.android.com/reference/java/lang/SecurityException

      Details in: https://developer.android.com/reference/android/app/Service#startForeground(int,%20android.app.Notification)