@Implements(android.app.Application.class) public class ShadowApplication extends ShadowContextWrapper
Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowApplication.Wrapper |
Constructor | Description |
---|---|
ShadowApplication() |
Modifier and Type | Method | Description |
---|---|---|
void |
addWakeLock(PowerManager.WakeLock wl) |
|
void |
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
calling
Context.startActivity(android.content.Intent) . |
void |
clearRegisteredReceivers() |
Clears the list of
ShadowApplication.Wrapper s for registered receivers |
void |
clearWakeLocks() |
|
void |
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 use
Context#getSystemService(Context.APPWIDGET_SERVICE) intstead. |
Scheduler |
getBackgroundThreadScheduler() |
Return the background scheduler.
|
Object |
getBluetoothAdapter() |
|
List<ServiceConnection> |
getBoundServiceConnections() |
|
Scheduler |
getForegroundThreadScheduler() |
Return the foreground scheduler.
|
static ShadowApplication |
getInstance() |
Deprecated.
Use
shadowOf({@link ApplicationProvider#getApplicationContext()}) instead. |
ShadowAlertDialog |
getLatestAlertDialog() |
Deprecated.
Use
ShadowAlertDialog.getLatestAlertDialog() instead. |
ShadowDialog |
getLatestDialog() |
Deprecated.
Use
ShadowDialog.getLatestDialog() instead. |
ListPopupWindow |
getLatestListPopupWindow() |
|
ShadowPopupMenu |
getLatestPopupMenu() |
Deprecated.
Use
ShadowPopupMenu.getLatestPopupMenu() instead. |
PopupWindow |
getLatestPopupWindow() |
|
PowerManager.WakeLock |
getLatestWakeLock() |
|
List<BroadcastReceiver> |
getReceiversForIntent(Intent intent) |
Deprecated.
use PackageManager.queryBroadcastReceivers instead
|
com.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 instead
|
static void |
runBackgroundTasks() |
Runs any background tasks previously queued by
AsyncTask.execute(Object[]) . |
void |
setComponentNameAndServiceForBindService(ComponentName name,
IBinder service) |
|
void |
setComponentNameAndServiceForBindServiceForIntent(Intent intent,
ComponentName name,
IBinder service) |
|
protected void |
setLatestAlertDialog(ShadowAlertDialog latestAlertDialog) |
|
protected void |
setLatestDialog(ShadowDialog latestDialog) |
|
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 by
Application.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. The preferered method is use the shadow of the corresponding service.
|
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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearBroadcastIntents, clearNextStartedActivities, clearStartedServices, denyPermissions, denyPermissions, getBroadcastIntents, getBroadcastIntentsForUser, getNextStartedActivity, getNextStartedActivityForResult, getNextStartedService, getNextStoppedService, grantPermissions, grantPermissions, peekNextStartedActivity, peekNextStartedActivityForResult, peekNextStartedService, removeSystemService
@Deprecated public static ShadowApplication getInstance()
shadowOf({@link ApplicationProvider#getApplicationContext()})
instead.public static void runBackgroundTasks()
AsyncTask.execute(Object[])
.
Note: calling this method does not pause or un-pause the scheduler.public static void setProcessName(String processName)
Application.getProcessName()
.public void callAttach(Context context)
context
- The context with which to initialize the application, whose base context will
be attached to the applicationpublic Scheduler getForegroundThreadScheduler()
public Scheduler getBackgroundThreadScheduler()
public void setUnbindServiceCallsOnServiceDisconnected(boolean flag)
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.public void setComponentNameAndServiceForBindService(ComponentName name, IBinder service)
public void setComponentNameAndServiceForBindServiceForIntent(Intent intent, ComponentName name, IBinder service)
public void assertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action)
public List<ServiceConnection> getBoundServiceConnections()
public void setUnbindServiceShouldThrowIllegalArgument(boolean flag)
public void setThrowInBindService(SecurityException e)
public List<ServiceConnection> getUnboundServiceConnections()
@Deprecated public boolean hasReceiverForIntent(Intent intent)
@Deprecated public List<BroadcastReceiver> getReceiversForIntent(Intent intent)
public com.google.common.collect.ImmutableList<ShadowApplication.Wrapper> getRegisteredReceivers()
ShadowApplication.Wrapper
s for registered receiverspublic void clearRegisteredReceivers()
ShadowApplication.Wrapper
s for registered receivers@Deprecated public AppWidgetManager getAppWidgetManager()
Context#getSystemService(Context.APPWIDGET_SERVICE)
intstead.@Deprecated public ShadowAlertDialog getLatestAlertDialog()
ShadowAlertDialog.getLatestAlertDialog()
instead.protected void setLatestAlertDialog(ShadowAlertDialog latestAlertDialog)
@Deprecated public ShadowDialog getLatestDialog()
ShadowDialog.getLatestDialog()
instead.protected void setLatestDialog(ShadowDialog latestDialog)
public Object getBluetoothAdapter()
public void declareActionUnbindable(String action)
public void declareComponentUnbindable(ComponentName component)
public PowerManager.WakeLock getLatestWakeLock()
public void addWakeLock(PowerManager.WakeLock wl)
public void clearWakeLocks()
public void checkActivities(boolean checkActivities)
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.@Deprecated public ShadowPopupMenu getLatestPopupMenu()
ShadowPopupMenu.getLatestPopupMenu()
instead.protected void setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)
public PopupWindow getLatestPopupWindow()
protected void setLatestPopupWindow(PopupWindow latestPopupWindow)
public ListPopupWindow getLatestListPopupWindow()
protected void setLatestListPopupWindow(ListPopupWindow latestListPopupWindow)
@Deprecated public void setSystemService(String key, Object service)