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 ClassesModifier and TypeClassDescriptionstatic classContainer object to hold an Intent, together with the requestCode used in a call toActivity.startActivityForResult(Intent, int)static classClass to holds details of a startIntentSenderForResult request.static classClass to hold overridden activity transition details after callingActivity.overrideActivityTransition(int, int, int, int)static classClass to hold a permissions request, including its request code. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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) voidcallAttach(Intent intent, Bundle activityOptions, Object lastNonConfigurationInstances, Configuration overrideConfig) voidcallOnActivityResult(int requestCode, int resultCode, Intent resultData) Deprecated.voidcallOnGetDirectActions(CancellationSignal cancellationSignal, Consumer<List<DirectAction>> callback) Calls Activity#onGetDirectActions with the given parameters.protected voidclearOverrideActivityTransition(int overrideType) booleanclickMenuItem(int menuItemResId) Perform a click on a menu item.protected voiddismissDialog(int id) protected voidprotected booleanprotected ViewfindViewById(int id) Checks to ensure that thecontentViewhas been setprotected voidfinish()protected voidprotected voidprotected ComponentNameprotected Stringprotected ViewintgetDialogById(int dialogId) Gets the last startIntentSenderForResult request made to this activity.protected ObjectGets the last permission request submitted to this activity.protected LayoutInflaterprotected MenuInflaterConsumes and returns the nextIntenton the started activities for results stack.Return the options menu.getOverriddenActivityTransition(int overrideType) Get the overriddenActivitytransition, set byActivity.overrideActivityTransition(int, int, int).protected Activityintintbooleanprotected intintbooleanprotected Objectprotected intbooleanprotected intprotected WindowConstructs a new Window (aPhoneWindow) if no window has previously been set.booleanvoidInitializes the associated Activity with anVoiceInteractorinstance.voidinternalCallDispatchActivityResult(String who, int requestCode, int resultCode, Intent data) For internal use only.protected booleanReturns whetherfinish()was called.protected booleanprotected booleanbooleanDeprecated.protected booleanprotected booleanmoveTaskToBack(boolean nonRoot) protected voidprotected booleanonCreateOptionsMenu(Menu menu) protected voidprotected voidoverrideActivityTransition(int overrideType, int enterAnim, int exitAnim, int backgroundColor) protected voidoverridePendingTransition(int enterAnim, int exitAnim) 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 voidprotected voidrequestPermissions(String[] permissions, int requestCode) voidprotected 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.voidAllow setting of Parent fragmentActivity (for unit testing purposes only)protected voidsetRequestedOrientation(int requestedOrientation) protected voidsetResult(int resultCode) protected voidprotected voidsetShowWhenLocked(boolean showWhenLocked) voidsetThrowIntentSenderException(boolean throwIntentSenderException) Sets if startIntentSenderForRequestCode will throw an IntentSender.SendIntentException.protected voidsetTurnScreenOn(boolean turnScreenOn) protected voidsetVolumeControlStream(int streamType) voidprotected 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 voidStarts a lock task.protected voidprotected voidStops a lock task.protected voidMethods inherited from class org.robolectric.shadows.ShadowContextThemeWrapper
callGetThemeResIdMethods 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 Details
-
realActivity
-
-
Constructor Details
-
ShadowActivity
public ShadowActivity()
-
-
Method Details
-
setApplication
-
callAttach
-
callAttach
-
callAttach
-
callAttach
public void callAttach(Intent intent, @Nullable Bundle activityOptions, @Nullable Object lastNonConfigurationInstances, @Nullable Configuration overrideConfig) -
setCallingActivity
Sets the calling activity that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage(). -
getCallingActivity
-
setCallingPackage
Sets the calling package that will be reflected inActivity.getCallingActivity()andActivity.getCallingPackage().Activity name defaults to some default value.
-
getCallingPackage
-
setDefaultKeyMode
-
getDefaultKeymode
public int getDefaultKeymode() -
setShowWhenLocked
-
getShowWhenLocked
-
setTurnScreenOn
-
getTurnScreenOn
-
setResult
-
setResult
-
getLayoutInflater
-
getMenuInflater
-
findViewById
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
-
setParent
Allow setting of Parent fragmentActivity (for unit testing purposes only)- Parameters:
parent- Parent fragmentActivity to set on this fragmentActivity
-
onBackPressed
-
finish
-
finishAndRemoveTask
-
finishAffinity
-
resetIsFinishing
public void resetIsFinishing() -
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
Constructs a new Window (aPhoneWindow) if no window has previously been set.- Returns:
- the window associated with this Activity
-
getSplashScreen
- Returns:
- fake SplashScreen
-
setWindow
-
runOnUiThread
-
setRequestedOrientation
-
getRequestedOrientation
-
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
-
getReportFullyDrawn
public boolean getReportFullyDrawn()- Returns:
- whether
ReportFullyDrawn()methods has been called.
-
getContentView
- Returns:
- the
contentViewset by one of thesetContentView()methods
-
getResultCode
public int getResultCode()- Returns:
- the
resultCodeset by one of thesetResult()methods
-
getResultIntent
- Returns:
- the
Intentset bysetResult(int, android.content.Intent)
-
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
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
-
setLastNonConfigurationInstance
Deprecated. -
setCurrentFocus
- Parameters:
view- View to focus.
-
getCurrentFocus
-
getPendingTransitionEnterAnimationResourceId
public int getPendingTransitionEnterAnimationResourceId() -
getPendingTransitionExitAnimationResourceId
public int getPendingTransitionExitAnimationResourceId() -
getOverriddenActivityTransition
@Nullable @RequiresApi(34) public ShadowActivity.OverriddenActivityTransition getOverriddenActivityTransition(int overrideType) Get the overriddenActivitytransition, set byActivity.overrideActivityTransition(int, int, int).- Parameters:
overrideType- UseActivity.OVERRIDE_TRANSITION_OPENto get the overridden activity transition animation details when starting/entering an activity. UseActivity.OVERRIDE_TRANSITION_CLOSEto get the overridden activity transition animation details when finishing/closing an activity.- Returns:
- overridden activity transition details after calling
Activity.overrideActivityTransition(int, int, int, int)or null if was not overridden. - See Also:
-
onCreateOptionsMenu
-
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. -
internalCallDispatchActivityResult
public void internalCallDispatchActivityResult(String who, int requestCode, int resultCode, Intent data) For internal use only. Not for public use. -
attachController
For internal use only. Not for public use. -
setThrowIntentSenderException
public void setThrowIntentSenderException(boolean throwIntentSenderException) Sets if startIntentSenderForRequestCode will throw an IntentSender.SendIntentException. -
receiveResult
-
showDialog
-
showDialog
-
dismissDialog
-
removeDialog
-
setIsTaskRoot
public void setIsTaskRoot(boolean isRoot) -
isTaskRoot
-
getLastShownDialogId
- Returns:
- the dialog resource id passed into
Activity.showDialog(int, Bundle)orActivity.showDialog(int)
-
hasCancelledPendingTransitions
public boolean hasCancelledPendingTransitions() -
overridePendingTransition
-
overrideActivityTransition
@Implementation(minSdk=34) protected void overrideActivityTransition(int overrideType, @AnimRes int enterAnim, @AnimRes int exitAnim, int backgroundColor) -
clearOverrideActivityTransition
-
getDialogById
-
onDestroy
-
recreate
-
startManagingCursor
-
stopManagingCursor
-
getManagedCursors
-
setVolumeControlStream
-
getVolumeControlStream
-
requestPermissions
-
startLockTask
Starts a lock task.The status of the lock task can be verified using
isLockTask()method. Otherwise this implementation has no effect. -
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.UseActivityManager.getLockTaskModeState()instead.Returns if the activity is in the lock task mode. -
setInMultiWindowMode
public void setInMultiWindowMode(boolean value) Changes state ofisInMultiWindowMode()method. -
isInMultiWindowMode
-
isInPictureInPictureMode
-
enterPictureInPictureMode
-
enterPictureInPictureMode
@Implementation(minSdk=26) protected boolean enterPictureInPictureMode(PictureInPictureParams params) -
moveTaskToBack
-
getLastIntentSenderRequest
Gets the last startIntentSenderForResult request made to this activity.- Returns:
- The IntentSender request details.
-
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.
-
ActivityManager.getLockTaskModeState()instead.