Package org.robolectric.shadows
Class ShadowActivity
- java.lang.Object
-
- org.robolectric.shadows.ShadowContextWrapper
-
- org.robolectric.shadows.ShadowContextThemeWrapper
-
- org.robolectric.shadows.ShadowActivity
-
- Direct Known Subclasses:
ShadowActivityGroup
@Implements(value=android.app.Activity.class, looseSignatures=true) public class ShadowActivity extends ShadowContextThemeWrapper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShadowActivity.IntentForResultContainer object to hold an Intent, together with the requestCode used in a call toActivity.startActivityForResult(Intent, int)static classShadowActivity.IntentSenderRequestClass to holds details of a startIntentSenderForResult request.static classShadowActivity.PermissionsRequestClass to hold a permissions request, including its request code.
-
Field Summary
Fields Modifier and Type Field Description protected ActivityrealActivity
-
Constructor Summary
Constructors Constructor Description ShadowActivity()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T extends Activity>
voidattachController(ActivityController controller)For internal use only.voidcallAttach(Intent intent)voidcallAttach(Intent intent, Bundle activityOptions)voidcallAttach(Intent intent, Bundle activityOptions, Object lastNonConfigurationInstances)voidcallOnActivityResult(int requestCode, int resultCode, Intent resultData)Deprecated.voidcallOnGetDirectActions(CancellationSignal cancellationSignal, Consumer<List<DirectAction>> callback)Calls Activity#onGetDirectActions with the given parameters.booleanclickMenuItem(int menuItemResId)Perform a click on a menu item.protected voiddismissDialog(int id)protected voidenterPictureInPictureMode()protected booleanenterPictureInPictureMode(PictureInPictureParams params)protected ViewfindViewById(int id)Checks to ensure that thecontentViewhas been setprotected voidfinish()protected voidfinishAffinity()protected voidfinishAndRemoveTask()protected ComponentNamegetCallingActivity()protected StringgetCallingPackage()ViewgetContentView()protected ViewgetCurrentFocus()intgetDefaultKeymode()DialoggetDialogById(int dialogId)ShadowActivity.IntentSenderRequestgetLastIntentSenderRequest()Gets the last startIntentSenderForResult request made to this activity.protected ObjectgetLastNonConfigurationInstance()ShadowActivity.PermissionsRequestgetLastRequestedPermission()Gets the last permission request submitted to this activity.IntegergetLastShownDialogId()protected LayoutInflatergetLayoutInflater()List<Cursor>getManagedCursors()protected MenuInflatergetMenuInflater()ShadowActivity.IntentForResultgetNextStartedActivityForResult()Consumes and returns the nextIntenton the started activities for results stack.MenugetOptionsMenu()Return the options menu.protected ActivitygetParent()intgetPendingTransitionEnterAnimationResourceId()intgetPendingTransitionExitAnimationResourceId()booleangetReportFullyDrawn()protected intgetRequestedOrientation()intgetResultCode()IntentgetResultIntent()protected ObjectgetSplashScreen()protected intgetTaskId()protected intgetVolumeControlStream()protected WindowgetWindow()Constructs a new Window (aPhoneWindow) if no window has previously been set.booleanhasCancelledPendingTransitions()voidinitializeVoiceInteractor()Initializes the associated Activity with anVoiceInteractorinstance.voidinternalCallDispatchActivityResult(String who, int requestCode, int resultCode, Intent data)For internal use only.protected booleanisFinishing()Returns whetherfinish()was called.protected booleanisInMultiWindowMode()protected booleanisInPictureInPictureMode()booleanisLockTask()Deprecated.UseActivityManager.getLockTaskModeState()instead.protected booleanisTaskRoot()protected booleanmoveTaskToBack(boolean nonRoot)protected voidonBackPressed()protected booleanonCreateOptionsMenu(Menu menu)protected voidonDestroy()protected voidoverridePendingTransition(int enterAnim, int exitAnim)ShadowActivity.IntentForResultpeekNextStartedActivityForResult()Returns the most recentIntentstarted byActivity.startActivityForResult(Intent, int)without consuming it.voidreceiveResult(Intent requestIntent, int resultCode, Intent resultIntent)protected voidrecreate()protected voidremoveDialog(int id)protected voidreportFullyDrawn()protected voidrequestPermissions(String[] permissions, int requestCode)voidresetIsFinishing()protected voidrunOnUiThread(Runnable action)voidsetApplication(Application application)voidsetCallingActivity(ComponentName activityName)Sets the calling activity that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage().voidsetCallingPackage(String packageName)Sets the calling package that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage().voidsetCurrentFocus(View view)protected voidsetDefaultKeyMode(int keyMode)voidsetInMultiWindowMode(boolean value)Changes state ofisInMultiWindowMode()method.voidsetIsTaskRoot(boolean isRoot)voidsetLastNonConfigurationInstance(Object lastNonConfigurationInstance)Deprecated.voidsetParent(Activity parent)Allow setting of Parent fragmentActivity (for unit testing purposes only)protected voidsetRequestedOrientation(int requestedOrientation)protected voidsetResult(int resultCode)protected voidsetResult(int resultCode, Intent data)voidsetThrowIntentSenderException(boolean throwIntentSenderException)Sets if startIntentSenderForRequestCode will throw an IntentSender.SendIntentException.protected voidsetVolumeControlStream(int streamType)voidsetWindow(Window window)protected voidshowDialog(int id)protected booleanshowDialog(int id, Bundle bundle)voidstartIntentSenderForResult(IntentSender intentSender, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)protected voidstartLockTask()Starts a lock task.protected voidstartManagingCursor(Cursor c)protected voidstopLockTask()Stops a lock task.protected voidstopManagingCursor(Cursor c)-
Methods inherited from class org.robolectric.shadows.ShadowContextThemeWrapper
callGetThemeResId
-
Methods inherited from class org.robolectric.shadows.ShadowContextWrapper
clearBroadcastIntents, clearNextStartedActivities, clearStartedServices, denyPermissions, denyPermissions, getAllStartedServices, getBroadcastIntents, getBroadcastIntentsForUser, getBroadcastOptions, getNextStartedActivity, getNextStartedService, getNextStoppedService, grantPermissions, grantPermissions, peekNextStartedActivity, peekNextStartedService, removeSystemService
-
-
-
-
Field Detail
-
realActivity
@RealObject protected Activity realActivity
-
-
Method Detail
-
setApplication
public void setApplication(Application application)
-
callAttach
public void callAttach(Intent intent)
-
callAttach
public void callAttach(Intent intent, @Nullable Bundle activityOptions, @Nullable Object lastNonConfigurationInstances)
-
setCallingActivity
public void setCallingActivity(@Nullable ComponentName activityName)
Sets the calling activity that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage().
-
getCallingActivity
@Implementation protected ComponentName getCallingActivity()
-
setCallingPackage
public void setCallingPackage(@Nullable String packageName)
Sets the calling package that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage().Activity name defaults to some default value.
-
getCallingPackage
@Implementation protected String getCallingPackage()
-
setDefaultKeyMode
@Implementation protected void setDefaultKeyMode(int keyMode)
-
getDefaultKeymode
public int getDefaultKeymode()
-
setResult
@Implementation protected final void setResult(int resultCode)
-
setResult
@Implementation protected final void setResult(int resultCode, Intent data)
-
getLayoutInflater
@Implementation protected LayoutInflater getLayoutInflater()
-
getMenuInflater
@Implementation protected MenuInflater getMenuInflater()
-
findViewById
@Implementation protected View findViewById(int id)
Checks to ensure that thecontentViewhas been set- Parameters:
id- ID of the view to find- Returns:
- the view
- Throws:
RuntimeException- if thecontentViewhas not been called first
-
getParent
@Implementation protected final Activity getParent()
-
setParent
@HiddenApi @Implementation public void setParent(Activity parent)
Allow setting of Parent fragmentActivity (for unit testing purposes only)- Parameters:
parent- Parent fragmentActivity to set on this fragmentActivity
-
onBackPressed
@Implementation protected void onBackPressed()
-
finish
@Implementation protected void finish()
-
finishAndRemoveTask
@Implementation(minSdk=21) protected void finishAndRemoveTask()
-
finishAffinity
@Implementation protected void finishAffinity()
-
resetIsFinishing
public void resetIsFinishing()
-
isFinishing
@Implementation(minSdk=16) protected boolean isFinishing()
Returns whetherfinish()was called.Note: this method seems redundant, but removing it will cause problems for Mockito spies of Activities that call
Activity.finish()followed byActivity.isFinishing(). This is because `finish` modifies the members ofrealActivity, so `isFinishing` should refer to those same members.
-
getWindow
@Implementation protected Window getWindow()
Constructs a new Window (aPhoneWindow) if no window has previously been set.- Returns:
- the window associated with this Activity
-
getSplashScreen
@Implementation(minSdk=31) protected Object getSplashScreen()
- Returns:
- fake SplashScreen
-
setWindow
public void setWindow(Window window)
-
runOnUiThread
@Implementation protected void runOnUiThread(Runnable action)
-
setRequestedOrientation
@Implementation protected void setRequestedOrientation(int requestedOrientation)
-
getRequestedOrientation
@Implementation protected int getRequestedOrientation()
-
getTaskId
@Implementation protected int getTaskId()
-
startIntentSenderForResult
@Implementation public void startIntentSenderForResult(IntentSender intentSender, int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException
- Throws:
IntentSender.SendIntentException
-
reportFullyDrawn
@Implementation(minSdk=19) protected void reportFullyDrawn()
-
getReportFullyDrawn
public boolean getReportFullyDrawn()
- Returns:
- whether
ReportFullyDrawn()methods has been called.
-
getContentView
public View getContentView()
- Returns:
- the
contentViewset by one of thesetContentView()methods
-
getResultCode
public int getResultCode()
- Returns:
- the
resultCodeset by one of thesetResult()methods
-
getResultIntent
public Intent getResultIntent()
- Returns:
- the
Intentset bysetResult(int, android.content.Intent)
-
getNextStartedActivityForResult
public ShadowActivity.IntentForResult getNextStartedActivityForResult()
Consumes and returns the nextIntenton the started activities for results stack.- Overrides:
getNextStartedActivityForResultin classShadowContextWrapper- Returns:
- the next started
Intentfor an activity, wrapped in anShadowActivity.IntentForResultobject
-
peekNextStartedActivityForResult
public ShadowActivity.IntentForResult peekNextStartedActivityForResult()
Returns the most recentIntentstarted byActivity.startActivityForResult(Intent, int)without consuming it.- Overrides:
peekNextStartedActivityForResultin classShadowContextWrapper- Returns:
- the most recently started
Intent, wrapped in anShadowActivity.IntentForResultobject
-
getLastNonConfigurationInstance
@Implementation protected Object getLastNonConfigurationInstance()
-
setLastNonConfigurationInstance
@Deprecated public void setLastNonConfigurationInstance(Object lastNonConfigurationInstance)
Deprecated.
-
setCurrentFocus
public void setCurrentFocus(View view)
- Parameters:
view- View to focus.
-
getCurrentFocus
@Implementation protected View getCurrentFocus()
-
getPendingTransitionEnterAnimationResourceId
public int getPendingTransitionEnterAnimationResourceId()
-
getPendingTransitionExitAnimationResourceId
public int getPendingTransitionExitAnimationResourceId()
-
onCreateOptionsMenu
@Implementation protected boolean onCreateOptionsMenu(Menu menu)
-
getOptionsMenu
public Menu getOptionsMenu()
Return the options menu.- Returns:
- Options menu.
-
clickMenuItem
public boolean clickMenuItem(int menuItemResId)
Perform a click on a menu item.- Parameters:
menuItemResId- Menu item resource ID.- Returns:
- True if the click was handled, false otherwise.
-
callOnActivityResult
@Deprecated public void callOnActivityResult(int requestCode, int resultCode, Intent resultData)
Deprecated.
-
internalCallDispatchActivityResult
public void internalCallDispatchActivityResult(String who, int requestCode, int resultCode, Intent data)
For internal use only. Not for public use.
-
attachController
public <T extends Activity> void attachController(ActivityController controller)
For internal use only. Not for public use.
-
setThrowIntentSenderException
public void setThrowIntentSenderException(boolean throwIntentSenderException)
Sets if startIntentSenderForRequestCode will throw an IntentSender.SendIntentException.
-
showDialog
@Implementation protected final void showDialog(int id)
-
dismissDialog
@Implementation protected final void dismissDialog(int id)
-
removeDialog
@Implementation protected final void removeDialog(int id)
-
showDialog
@Implementation protected final boolean showDialog(int id, Bundle bundle)
-
setIsTaskRoot
public void setIsTaskRoot(boolean isRoot)
-
isTaskRoot
@Implementation protected final boolean isTaskRoot()
-
getLastShownDialogId
public Integer getLastShownDialogId()
- Returns:
- the dialog resource id passed into
Activity.showDialog(int, Bundle)orActivity.showDialog(int)
-
hasCancelledPendingTransitions
public boolean hasCancelledPendingTransitions()
-
overridePendingTransition
@Implementation protected void overridePendingTransition(int enterAnim, int exitAnim)
-
getDialogById
public Dialog getDialogById(int dialogId)
-
onDestroy
@Implementation protected void onDestroy()
-
recreate
@Implementation protected void recreate()
-
startManagingCursor
@Implementation protected void startManagingCursor(Cursor c)
-
stopManagingCursor
@Implementation protected void stopManagingCursor(Cursor c)
-
setVolumeControlStream
@Implementation protected final void setVolumeControlStream(int streamType)
-
getVolumeControlStream
@Implementation protected final int getVolumeControlStream()
-
requestPermissions
@Implementation(minSdk=23) protected final void requestPermissions(String[] permissions, int requestCode)
-
startLockTask
@Implementation(minSdk=21) protected void startLockTask()
Starts a lock task.The status of the lock task can be verified using
isLockTask()method. Otherwise this implementation has no effect.
-
stopLockTask
@Implementation(minSdk=21) protected void stopLockTask()
Stops a lock task.The status of the lock task can be verified using
isLockTask()method. Otherwise this implementation has no effect.
-
isLockTask
@Deprecated public boolean isLockTask()
Deprecated.UseActivityManager.getLockTaskModeState()instead.Returns if the activity is in the lock task mode.
-
setInMultiWindowMode
public void setInMultiWindowMode(boolean value)
Changes state ofisInMultiWindowMode()method.
-
isInMultiWindowMode
@Implementation(minSdk=24) protected boolean isInMultiWindowMode()
-
isInPictureInPictureMode
@Implementation(minSdk=24) protected boolean isInPictureInPictureMode()
-
enterPictureInPictureMode
@Implementation(minSdk=24) protected void enterPictureInPictureMode()
-
enterPictureInPictureMode
@Implementation(minSdk=26) protected boolean enterPictureInPictureMode(PictureInPictureParams params)
-
moveTaskToBack
@Implementation protected boolean moveTaskToBack(boolean nonRoot)
-
getLastIntentSenderRequest
public ShadowActivity.IntentSenderRequest getLastIntentSenderRequest()
Gets the last startIntentSenderForResult request made to this activity.- Returns:
- The IntentSender request details.
-
getLastRequestedPermission
public ShadowActivity.PermissionsRequest getLastRequestedPermission()
Gets the last permission request submitted to this activity.- Returns:
- The permission request details.
-
initializeVoiceInteractor
public void initializeVoiceInteractor()
Initializes the associated Activity with anVoiceInteractorinstance. SubsequentActivity.getVoiceInteractor()calls on the associated activity will return aVoiceInteractorinstance
-
callOnGetDirectActions
public void callOnGetDirectActions(CancellationSignal cancellationSignal, Consumer<List<DirectAction>> callback)
Calls Activity#onGetDirectActions with the given parameters. This method also simulates the Parcel serialization/deserialization which occurs when assistant requests DirectAction.
-
-