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 SummaryNested Classes
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidDeprecated.use PowerManager APIs insteadvoidassertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action) voidcallAttach(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).voidClears the list ofShadowApplication.Wrappers for registered receiversvoidDeprecated.use ShadowPowerManager.clearWakeLocksvoiddeclareActionUnbindable(String action) voiddeclareComponentUnbindable(ComponentName component) Configures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.Deprecated.Please useContext.getSystemService(Context.APPWIDGET_SERVICE)intstead.Deprecated.Deprecated.UseBluetoothAdapter.getDefaultAdapter()()} instead.Deprecated.static ShadowApplicationDeprecated.UseshadowOf({@link ApplicationProvider#getApplicationContext()})instead.Deprecated.UseShadowAlertDialog.getLatestAlertDialog()instead.Deprecated.UseShadowDialog.getLatestDialog()instead.Deprecated.UseShadowPopupMenu.getLatestPopupMenu()instead.Deprecated.use ShadowPowerManager.getLatestWakeLockgetReceiversForIntent(Intent intent) Deprecated.use PackageManager.queryBroadcastReceivers insteadcom.google.common.collect.ImmutableList<ShadowApplication.Wrapper><T> TgetSingleton(Class<T> clazz, Provider<T> provider) booleanhasReceiverForIntent(Intent intent) Deprecated.use PackageManager.queryBroadcastReceivers insteadstatic voidRuns any background tasks previously queued byAsyncTask.execute(Object[]).voidsetBindServiceCallsOnServiceConnectedDirectly(boolean callDirectly) Configures the ShadowApplication so that calls to bindService will call ServiceConnection#onServiceConnected before returning.voidsetComponentNameAndServiceForBindService(ComponentName name, IBinder service) voidsetComponentNameAndServiceForBindServiceForIntent(Intent intent, ComponentName name, IBinder service) protected voidsetLatestListPopupWindow(ListPopupWindow latestListPopupWindow) protected voidsetLatestPopupMenu(ShadowPopupMenu latestPopupMenu) protected voidsetLatestPopupWindow(PopupWindow latestPopupWindow) static voidsetProcessName(String processName) Configures the value to be returned byApplication.getProcessName().voidsetSystemService(String key, Object service) Deprecated.Do not depend on this method to override services as it will be removed in a future update.voidConfigures 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.ShadowContextWrapperclearBroadcastIntents, clearNextStartedActivities, clearStartedServices, denyPermissions, denyPermissions, getAllStartedServices, getBroadcastIntents, getBroadcastIntentsForUser, getBroadcastOptions, getNextStartedActivity, getNextStartedActivityForResult, getNextStartedService, getNextStoppedService, grantPermissions, grantPermissions, peekNextStartedActivity, peekNextStartedActivityForResult, peekNextStartedService, removeSystemService
- 
Constructor Details- 
ShadowApplicationpublic ShadowApplication()
 
- 
- 
Method Details- 
getInstanceDeprecated.UseshadowOf({@link ApplicationProvider#getApplicationContext()})instead.
- 
runBackgroundTaskspublic static void runBackgroundTasks()Runs any background tasks previously queued byAsyncTask.execute(Object[]).Note: calling this method does not pause or un-pause the scheduler. 
- 
setProcessNameConfigures the value to be returned byApplication.getProcessName().
- 
callAttachAttaches 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
- 
getForegroundThreadSchedulerDeprecated.Return the foreground scheduler.- Returns:
- Foreground scheduler.
 
- 
getBackgroundThreadSchedulerDeprecated.Return the background scheduler.- Returns:
- Background scheduler.
 
- 
setUnbindServiceCallsOnServiceDisconnectedpublic void setUnbindServiceCallsOnServiceDisconnected(boolean flag) Sets whether or not calls to unbindService should call onServiceDisconnected().The default for this is currently truebecause 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
- 
setComponentNameAndServiceForBindServiceForIntentpublic void setComponentNameAndServiceForBindServiceForIntent(Intent intent, ComponentName name, IBinder service) 
- 
assertNoBroadcastListenersOfActionRegistered
- 
getBoundServiceConnections
- 
setUnbindServiceShouldThrowIllegalArgumentpublic void setUnbindServiceShouldThrowIllegalArgument(boolean flag) 
- 
setThrowInBindServiceConfigures the ShadowApplication so that calls to bindService will throw the given SecurityException.
- 
setBindServiceCallsOnServiceConnectedDirectlypublic void setBindServiceCallsOnServiceConnectedDirectly(boolean callDirectly) Configures the ShadowApplication so that calls to bindService will call ServiceConnection#onServiceConnected before returning.
- 
getUnboundServiceConnections
- 
hasReceiverForIntentDeprecated.use PackageManager.queryBroadcastReceivers instead
- 
getReceiversForIntentDeprecated.use PackageManager.queryBroadcastReceivers instead
- 
getRegisteredReceivers- Returns:
- list of ShadowApplication.Wrappers for registered receivers
 
- 
clearRegisteredReceiverspublic void clearRegisteredReceivers()Clears the list ofShadowApplication.Wrappers for registered receivers
- 
getAppWidgetManagerDeprecated.Please useContext.getSystemService(Context.APPWIDGET_SERVICE)intstead.
- 
getLatestAlertDialogDeprecated.UseShadowAlertDialog.getLatestAlertDialog()instead.
- 
getLatestDialogDeprecated.UseShadowDialog.getLatestDialog()instead.
- 
getBluetoothAdapterDeprecated.UseBluetoothAdapter.getDefaultAdapter()()} instead.
- 
declareActionUnbindable
- 
declareComponentUnbindableConfigures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.
- 
getLatestWakeLockDeprecated.use ShadowPowerManager.getLatestWakeLock
- 
addWakeLockDeprecated.use PowerManager APIs instead
- 
clearWakeLocksDeprecated.use ShadowPowerManager.clearWakeLocks
- 
getSingleton
- 
checkActivitiespublic 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.
 
- 
getLatestPopupMenuDeprecated.UseShadowPopupMenu.getLatestPopupMenu()instead.
- 
setLatestPopupMenu
- 
getLatestPopupWindow
- 
setLatestPopupWindow
- 
getLatestListPopupWindow
- 
setLatestListPopupWindow
- 
setSystemServiceDeprecated.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.
 
-