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 class
ShadowApplication.Wrapper
-
Constructor Summary
Constructors Constructor Description ShadowApplication()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addWakeLock(PowerManager.WakeLock wl)
Deprecated.use PowerManager APIs insteadvoid
assertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action)
void
callAttach(Context context)
Attaches an application to a base context.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)
.void
clearRegisteredReceivers()
Clears the list ofShadowApplication.Wrapper
s for registered receiversvoid
clearWakeLocks()
Deprecated.use ShadowPowerManager.clearWakeLocksvoid
declareActionUnbindable(String action)
void
declareComponentUnbindable(ComponentName component)
Configures the ShadowApplication so that bindService calls for the given ComponentName return false and do not call onServiceConnected.AppWidgetManager
getAppWidgetManager()
Deprecated.Please useContext#getSystemService(Context.APPWIDGET_SERVICE)
intstead.Scheduler
getBackgroundThreadScheduler()
Deprecated.BluetoothAdapter
getBluetoothAdapter()
Deprecated.UseBluetoothAdapter.getDefaultAdapter()
()} instead.List<ServiceConnection>
getBoundServiceConnections()
Scheduler
getForegroundThreadScheduler()
Deprecated.static ShadowApplication
getInstance()
Deprecated.UseshadowOf({@link ApplicationProvider#getApplicationContext()})
instead.ShadowAlertDialog
getLatestAlertDialog()
Deprecated.UseShadowAlertDialog.getLatestAlertDialog()
instead.ShadowDialog
getLatestDialog()
Deprecated.UseShadowDialog.getLatestDialog()
instead.ListPopupWindow
getLatestListPopupWindow()
ShadowPopupMenu
getLatestPopupMenu()
Deprecated.UseShadowPopupMenu.getLatestPopupMenu()
instead.PopupWindow
getLatestPopupWindow()
PowerManager.WakeLock
getLatestWakeLock()
Deprecated.use ShadowPowerManager.getLatestWakeLockList<BroadcastReceiver>
getReceiversForIntent(Intent intent)
Deprecated.use PackageManager.queryBroadcastReceivers insteadcom.google.common.collect.ImmutableList<ShadowApplication.Wrapper>
getRegisteredReceivers()
List<Toast>
getShownToasts()
<T> T
getSingleton(Class<T> clazz, Provider<T> provider)
List<ServiceConnection>
getUnboundServiceConnections()
boolean
hasReceiverForIntent(Intent intent)
Deprecated.use PackageManager.queryBroadcastReceivers insteadstatic void
runBackgroundTasks()
Runs any background tasks previously queued byAsyncTask.execute(Object[])
.void
setBindServiceCallsOnServiceConnectedDirectly(boolean callDirectly)
Configures the ShadowApplication so that calls to bindService will call ServiceConnection#onServiceConnected before returning.void
setComponentNameAndServiceForBindService(ComponentName name, IBinder service)
void
setComponentNameAndServiceForBindServiceForIntent(Intent intent, ComponentName name, IBinder service)
protected void
setLatestListPopupWindow(ListPopupWindow latestListPopupWindow)
protected void
setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)
protected void
setLatestPopupWindow(PopupWindow latestPopupWindow)
static void
setProcessName(String processName)
Configures the value to be returned byApplication.getProcessName()
.void
setSystemService(String key, Object service)
Deprecated.Do not depend on this method to override services as it will be removed in a future update.void
setThrowInBindService(SecurityException e)
Configures the ShadowApplication so that calls to bindService will throw the given SecurityException.void
setUnbindServiceCallsOnServiceDisconnected(boolean flag)
Sets whether or not calls to unbindService should call onServiceDisconnected().void
setUnbindServiceShouldThrowIllegalArgument(boolean flag)
-
Methods inherited from class org.robolectric.shadows.ShadowContextWrapper
clearBroadcastIntents, clearNextStartedActivities, clearStartedServices, denyPermissions, denyPermissions, getAllStartedServices, getBroadcastIntents, getBroadcastIntentsForUser, getBroadcastOptions, 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(String processName)
Configures the value to be returned byApplication.getProcessName()
.
-
callAttach
public void callAttach(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
-
getForegroundThreadScheduler
@Deprecated public Scheduler getForegroundThreadScheduler()
Deprecated.Return the foreground scheduler.- Returns:
- Foreground scheduler.
-
getBackgroundThreadScheduler
@Deprecated public Scheduler getBackgroundThreadScheduler()
Deprecated.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 currently
true
because that is the historical behavior. However, this does not correctly mirror Android's actual behavior. This value will eventually default tofalse
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)
Deprecated.use PackageManager.queryBroadcastReceivers instead
-
getReceiversForIntent
@Deprecated public List<BroadcastReceiver> getReceiversForIntent(Intent intent)
Deprecated.use PackageManager.queryBroadcastReceivers instead
-
getRegisteredReceivers
public com.google.common.collect.ImmutableList<ShadowApplication.Wrapper> getRegisteredReceivers()
- Returns:
- list of
ShadowApplication.Wrapper
s for registered receivers
-
clearRegisteredReceivers
public void clearRegisteredReceivers()
Clears the list ofShadowApplication.Wrapper
s for registered receivers
-
getAppWidgetManager
@Deprecated public AppWidgetManager getAppWidgetManager()
Deprecated.Please useContext#getSystemService(Context.APPWIDGET_SERVICE)
intstead.
-
getLatestAlertDialog
@Deprecated public ShadowAlertDialog getLatestAlertDialog()
Deprecated.UseShadowAlertDialog.getLatestAlertDialog()
instead.
-
getLatestDialog
@Deprecated public ShadowDialog getLatestDialog()
Deprecated.UseShadowDialog.getLatestDialog()
instead.
-
getBluetoothAdapter
@Deprecated public final BluetoothAdapter getBluetoothAdapter()
Deprecated.UseBluetoothAdapter.getDefaultAdapter()
()} instead.
-
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()
Deprecated.use ShadowPowerManager.getLatestWakeLock
-
addWakeLock
@Deprecated public void addWakeLock(PowerManager.WakeLock wl)
Deprecated.use PowerManager APIs instead
-
clearWakeLocks
@Deprecated public void clearWakeLocks()
Deprecated.use ShadowPowerManager.clearWakeLocks
-
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 aActivityNotFoundException
if given anIntent
that is not known to thePackageManager
By 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 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)
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.
-
-