Package org.robolectric.shadows
Class ShadowApplication
- java.lang.Object
-
- org.robolectric.shadows.ShadowContextWrapper
-
- org.robolectric.shadows.ShadowApplication
-
@Implements(android.app.Application.class) public class ShadowApplication extends ShadowContextWrapper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShadowApplication.Wrapper
-
Constructor Summary
Constructors Constructor Description ShadowApplication()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddWakeLock(android.os.PowerManager.WakeLock wl)voidassertNoBroadcastListenersOfActionRegistered(android.content.ContextWrapper context, java.lang.String action)voidcallAttach(android.content.Context context)Attaches an application to a base context.voidcheckActivities(boolean checkActivities)Set to true if you'd like Robolectric to strictly simulate the real Android behavior when callingContext.startActivity(android.content.Intent).voidclearRegisteredReceivers()Clears the list ofShadowApplication.Wrappers for registered receiversvoidclearWakeLocks()voiddeclareActionUnbindable(java.lang.String action)voiddeclareComponentUnbindable(android.content.ComponentName component)Configures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.android.appwidget.AppWidgetManagergetAppWidgetManager()Deprecated.Please useContext#getSystemService(Context.APPWIDGET_SERVICE)intstead.org.robolectric.util.SchedulergetBackgroundThreadScheduler()Return the background scheduler.java.lang.ObjectgetBluetoothAdapter()java.util.List<android.content.ServiceConnection>getBoundServiceConnections()org.robolectric.util.SchedulergetForegroundThreadScheduler()Return the foreground scheduler.static ShadowApplicationgetInstance()Deprecated.UseshadowOf({@link ApplicationProvider#getApplicationContext()})instead.ShadowAlertDialoggetLatestAlertDialog()Deprecated.UseShadowAlertDialog.getLatestAlertDialog()instead.ShadowDialoggetLatestDialog()Deprecated.UseShadowDialog.getLatestDialog()instead.android.widget.ListPopupWindowgetLatestListPopupWindow()ShadowPopupMenugetLatestPopupMenu()Deprecated.UseShadowPopupMenu.getLatestPopupMenu()instead.android.widget.PopupWindowgetLatestPopupWindow()android.os.PowerManager.WakeLockgetLatestWakeLock()java.util.List<android.content.BroadcastReceiver>getReceiversForIntent(android.content.Intent intent)Deprecated.use PackageManager.queryBroadcastReceivers insteadcom.google.common.collect.ImmutableList<ShadowApplication.Wrapper>getRegisteredReceivers()java.util.List<android.widget.Toast>getShownToasts()<T> TgetSingleton(java.lang.Class<T> clazz, Provider<T> provider)java.util.List<android.content.ServiceConnection>getUnboundServiceConnections()booleanhasReceiverForIntent(android.content.Intent intent)Deprecated.use PackageManager.queryBroadcastReceivers insteadstatic voidrunBackgroundTasks()Runs any background tasks previously queued byAsyncTask.execute(Object[]).voidsetComponentNameAndServiceForBindService(android.content.ComponentName name, android.os.IBinder service)voidsetComponentNameAndServiceForBindServiceForIntent(android.content.Intent intent, android.content.ComponentName name, android.os.IBinder service)protected voidsetLatestAlertDialog(ShadowAlertDialog latestAlertDialog)protected voidsetLatestDialog(ShadowDialog latestDialog)protected voidsetLatestListPopupWindow(android.widget.ListPopupWindow latestListPopupWindow)protected voidsetLatestPopupMenu(ShadowPopupMenu latestPopupMenu)protected voidsetLatestPopupWindow(android.widget.PopupWindow latestPopupWindow)static voidsetProcessName(java.lang.String processName)Configures the value to be returned byApplication.getProcessName().voidsetSystemService(java.lang.String key, java.lang.Object service)Deprecated.Do not depend on this method to override services as it will be removed in a future update.voidsetThrowInBindService(java.lang.SecurityException e)Configures the ShadowApplication so that calls to bindService will throw the given SecurityException.voidsetUnbindServiceCallsOnServiceDisconnected(boolean flag)Sets whether or not calls to unbindService should call onServiceDisconnected().voidsetUnbindServiceShouldThrowIllegalArgument(boolean flag)-
Methods inherited from class org.robolectric.shadows.ShadowContextWrapper
clearBroadcastIntents, clearNextStartedActivities, clearStartedServices, denyPermissions, denyPermissions, getBroadcastIntents, getBroadcastIntentsForUser, getNextStartedActivity, getNextStartedActivityForResult, getNextStartedService, getNextStoppedService, grantPermissions, grantPermissions, peekNextStartedActivity, peekNextStartedActivityForResult, peekNextStartedService, removeSystemService
-
-
-
-
Method Detail
-
getInstance
@Deprecated public static ShadowApplication getInstance()
Deprecated.UseshadowOf({@link ApplicationProvider#getApplicationContext()})instead.
-
runBackgroundTasks
public static void runBackgroundTasks()
Runs any background tasks previously queued byAsyncTask.execute(Object[]). Note: calling this method does not pause or un-pause the scheduler.
-
setProcessName
public static void setProcessName(java.lang.String processName)
Configures the value to be returned byApplication.getProcessName().
-
callAttach
public void callAttach(android.content.Context context)
Attaches an application to a base context.- Parameters:
context- The context with which to initialize the application, whose base context will be attached to the application
-
getShownToasts
public java.util.List<android.widget.Toast> getShownToasts()
-
getForegroundThreadScheduler
public org.robolectric.util.Scheduler getForegroundThreadScheduler()
Return the foreground scheduler.- Returns:
- Foreground scheduler.
-
getBackgroundThreadScheduler
public org.robolectric.util.Scheduler getBackgroundThreadScheduler()
Return the background scheduler.- Returns:
- Background scheduler.
-
setUnbindServiceCallsOnServiceDisconnected
public void setUnbindServiceCallsOnServiceDisconnected(boolean flag)
Sets whether or not calls to unbindService should call onServiceDisconnected(). The default for this is currentlytruebecause that is the historical behavior. However, this does not correctly mirror Android's actual behavior. This value will eventually default tofalseonce users have had a chance to migrate, and eventually the option will be removed altogether.
-
setComponentNameAndServiceForBindService
public void setComponentNameAndServiceForBindService(android.content.ComponentName name, android.os.IBinder service)
-
setComponentNameAndServiceForBindServiceForIntent
public void setComponentNameAndServiceForBindServiceForIntent(android.content.Intent intent, android.content.ComponentName name, android.os.IBinder service)
-
assertNoBroadcastListenersOfActionRegistered
public void assertNoBroadcastListenersOfActionRegistered(android.content.ContextWrapper context, java.lang.String action)
-
getBoundServiceConnections
public java.util.List<android.content.ServiceConnection> getBoundServiceConnections()
-
setUnbindServiceShouldThrowIllegalArgument
public void setUnbindServiceShouldThrowIllegalArgument(boolean flag)
-
setThrowInBindService
public void setThrowInBindService(java.lang.SecurityException e)
Configures the ShadowApplication so that calls to bindService will throw the given SecurityException.
-
getUnboundServiceConnections
public java.util.List<android.content.ServiceConnection> getUnboundServiceConnections()
-
hasReceiverForIntent
@Deprecated public boolean hasReceiverForIntent(android.content.Intent intent)
Deprecated.use PackageManager.queryBroadcastReceivers instead
-
getReceiversForIntent
@Deprecated public java.util.List<android.content.BroadcastReceiver> getReceiversForIntent(android.content.Intent intent)
Deprecated.use PackageManager.queryBroadcastReceivers instead
-
getRegisteredReceivers
public com.google.common.collect.ImmutableList<ShadowApplication.Wrapper> getRegisteredReceivers()
- Returns:
- list of
ShadowApplication.Wrappers for registered receivers
-
clearRegisteredReceivers
public void clearRegisteredReceivers()
Clears the list ofShadowApplication.Wrappers for registered receivers
-
getAppWidgetManager
@Deprecated public android.appwidget.AppWidgetManager getAppWidgetManager()
Deprecated.Please useContext#getSystemService(Context.APPWIDGET_SERVICE)intstead.
-
getLatestAlertDialog
@Deprecated public ShadowAlertDialog getLatestAlertDialog()
Deprecated.UseShadowAlertDialog.getLatestAlertDialog()instead.
-
setLatestAlertDialog
protected void setLatestAlertDialog(ShadowAlertDialog latestAlertDialog)
-
getLatestDialog
@Deprecated public ShadowDialog getLatestDialog()
Deprecated.UseShadowDialog.getLatestDialog()instead.
-
setLatestDialog
protected void setLatestDialog(ShadowDialog latestDialog)
-
getBluetoothAdapter
public java.lang.Object getBluetoothAdapter()
-
declareActionUnbindable
public void declareActionUnbindable(java.lang.String action)
-
declareComponentUnbindable
public void declareComponentUnbindable(android.content.ComponentName component)
Configures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.
-
getLatestWakeLock
public android.os.PowerManager.WakeLock getLatestWakeLock()
-
addWakeLock
public void addWakeLock(android.os.PowerManager.WakeLock wl)
-
clearWakeLocks
public void clearWakeLocks()
-
getSingleton
public <T> T getSingleton(java.lang.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 callingContext.startActivity(android.content.Intent). Real Android throws aActivityNotFoundExceptionif given anIntentthat is not known to thePackageManagerBy default, this behavior is off (false).- Parameters:
checkActivities- True to validate activities.
-
getLatestPopupMenu
@Deprecated public ShadowPopupMenu getLatestPopupMenu()
Deprecated.UseShadowPopupMenu.getLatestPopupMenu()instead.
-
setLatestPopupMenu
protected void setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)
-
getLatestPopupWindow
public android.widget.PopupWindow getLatestPopupWindow()
-
setLatestPopupWindow
protected void setLatestPopupWindow(android.widget.PopupWindow latestPopupWindow)
-
getLatestListPopupWindow
public android.widget.ListPopupWindow getLatestListPopupWindow()
-
setLatestListPopupWindow
protected void setLatestListPopupWindow(android.widget.ListPopupWindow latestListPopupWindow)
-
setSystemService
@Deprecated public void setSystemService(java.lang.String key, java.lang.Object service)Deprecated.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.
-
-