Class ShadowApplication


@Implements( public class ShadowApplication extends ShadowContextWrapper
  • Constructor Details

    • ShadowApplication

      public ShadowApplication()
  • Method Details

    • getInstance

      @Deprecated public static ShadowApplication getInstance()
      Use shadowOf({@link ApplicationProvider#getApplicationContext()}) instead.
    • runBackgroundTasks

      public static void runBackgroundTasks()
      Runs any background tasks previously queued by AsyncTask.execute(Object[]).

      Note: calling this method does not pause or un-pause the scheduler.

    • setProcessName

      public static void setProcessName(String processName)
      Configures the value to be returned by Application.getProcessName().
    • callAttach

      public void callAttach(Context context)
      Attaches an application to a base context.
      context - The context with which to initialize the application, whose base context will be attached to the application
    • getShownToasts

      public List<Toast> getShownToasts()
    • getForegroundThreadScheduler

      @Deprecated public Scheduler getForegroundThreadScheduler()
      Return the foreground scheduler.
      Foreground scheduler.
    • getBackgroundThreadScheduler

      @Deprecated public Scheduler getBackgroundThreadScheduler()
      Return the background scheduler.
      Background scheduler.
    • setUnbindServiceCallsOnServiceDisconnected

      public void setUnbindServiceCallsOnServiceDisconnected(boolean flag)
      Sets whether or not calls to unbindService should call onServiceDisconnected().

      The default for this is currently true because that is the historical behavior. However, this does not correctly mirror Android's actual behavior. This value will eventually default to false once users have had a chance to migrate, and eventually the option will be removed altogether.

    • setComponentNameAndServiceForBindService

      public void setComponentNameAndServiceForBindService(ComponentName name, IBinder service)
    • setComponentNameAndServiceForBindServiceForIntent

      public void setComponentNameAndServiceForBindServiceForIntent(Intent intent, ComponentName name, IBinder service)
    • assertNoBroadcastListenersOfActionRegistered

      public void assertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action)
    • getBoundServiceConnections

      public List<ServiceConnection> getBoundServiceConnections()
    • setUnbindServiceShouldThrowIllegalArgument

      public void setUnbindServiceShouldThrowIllegalArgument(boolean flag)
    • setThrowInBindService

      public void setThrowInBindService(SecurityException e)
      Configures the ShadowApplication so that calls to bindService will throw the given SecurityException.
    • setBindServiceCallsOnServiceConnectedDirectly

      public void setBindServiceCallsOnServiceConnectedDirectly(boolean callDirectly)
      Configures the ShadowApplication so that calls to bindService will call ServiceConnection#onServiceConnected before returning.
    • getUnboundServiceConnections

      public List<ServiceConnection> getUnboundServiceConnections()
    • hasReceiverForIntent

      @Deprecated public boolean hasReceiverForIntent(Intent intent)
      use PackageManager.queryBroadcastReceivers instead
    • getReceiversForIntent

      @Deprecated public List<BroadcastReceiver> getReceiversForIntent(Intent intent)
      use PackageManager.queryBroadcastReceivers instead
    • getRegisteredReceivers

      public<ShadowApplication.Wrapper> getRegisteredReceivers()
      list of ShadowApplication.Wrappers for registered receivers
    • clearRegisteredReceivers

      public void clearRegisteredReceivers()
      Clears the list of ShadowApplication.Wrappers for registered receivers
    • getAppWidgetManager

      @Deprecated public AppWidgetManager getAppWidgetManager()
    • getLatestAlertDialog

      @Deprecated public ShadowAlertDialog getLatestAlertDialog()
    • getLatestDialog

      @Deprecated public ShadowDialog getLatestDialog()
    • getBluetoothAdapter

      @Deprecated public BluetoothAdapter getBluetoothAdapter()
    • declareActionUnbindable

      public void declareActionUnbindable(String action)
    • declareComponentUnbindable

      public void declareComponentUnbindable(ComponentName component)
      Configures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.
    • getLatestWakeLock

      @Deprecated public PowerManager.WakeLock getLatestWakeLock()
      use ShadowPowerManager.getLatestWakeLock
    • addWakeLock

      @Deprecated public void addWakeLock(PowerManager.WakeLock wl)
      use PowerManager APIs instead
    • clearWakeLocks

      @Deprecated public void clearWakeLocks()
      use ShadowPowerManager.clearWakeLocks
    • getSingleton

      public <T> T getSingleton(Class<T> clazz, Provider<T> provider)
    • checkActivities

      public void checkActivities(boolean checkActivities)
      Set to true if you'd like Robolectric to strictly simulate the real Android behavior when calling Context.startActivity(android.content.Intent). Real Android throws a ActivityNotFoundException if given an Intent that is not known to the PackageManager

      By default, this behavior is off (false).

      checkActivities - True to validate activities.
    • getLatestPopupMenu

      @Deprecated public ShadowPopupMenu getLatestPopupMenu()
    • setLatestPopupMenu

      protected void setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)
    • getLatestPopupWindow

      public PopupWindow getLatestPopupWindow()
    • setLatestPopupWindow

      protected void setLatestPopupWindow(PopupWindow latestPopupWindow)
    • getLatestListPopupWindow

      public ListPopupWindow getLatestListPopupWindow()
    • setLatestListPopupWindow

      protected void setLatestListPopupWindow(ListPopupWindow latestListPopupWindow)
    • setSystemService

      @Deprecated public void setSystemService(String key, Object service)
      Do not depend on this method to override services as it will be removed in a future update. The preferered method is use the shadow of the corresponding service.