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(android.app.Activity.class) public class ShadowActivity extends ShadowContextThemeWrapper
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowActivity.IntentForResult
Container object to hold an Intent, together with the requestCode used in a call toActivity.startActivityForResult(Intent, int)
static class
ShadowActivity.IntentSenderRequest
Class to holds details of a startIntentSenderForResult request.static class
ShadowActivity.PermissionsRequest
Class to hold a permissions request, including its request code. -
Field Summary
Fields Modifier and Type Field Description protected Activity
realActivity
-
Constructor Summary
Constructors Constructor Description ShadowActivity()
-
Method Summary
Modifier and Type Method Description <T extends Activity>
voidattachController(ActivityController controller)
For internal use only.void
callAttach(Intent intent)
void
callAttach(Intent intent, Object lastNonConfigurationInstances)
void
callOnActivityResult(int requestCode, int resultCode, Intent resultData)
Deprecated.boolean
clickMenuItem(int menuItemResId)
Perform a click on a menu item.protected void
dismissDialog(int id)
protected void
enterPictureInPictureMode()
protected boolean
enterPictureInPictureMode(PictureInPictureParams params)
protected View
findViewById(int id)
Checks to ensure that thecontentView
has been setprotected void
finish()
protected void
finishAffinity()
protected void
finishAndRemoveTask()
protected ComponentName
getCallingActivity()
protected String
getCallingPackage()
View
getContentView()
protected View
getCurrentFocus()
int
getDefaultKeymode()
Dialog
getDialogById(int dialogId)
ShadowActivity.IntentSenderRequest
getLastIntentSenderRequest()
Gets the last startIntentSenderForResult request made to this activity.protected Object
getLastNonConfigurationInstance()
ShadowActivity.PermissionsRequest
getLastRequestedPermission()
Gets the last permission request submitted to this activity.Integer
getLastShownDialogId()
protected LayoutInflater
getLayoutInflater()
List<Cursor>
getManagedCursors()
protected MenuInflater
getMenuInflater()
ShadowActivity.IntentForResult
getNextStartedActivityForResult()
Consumes and returns the nextIntent
on the started activities for results stack.Menu
getOptionsMenu()
Return the options menu.protected Activity
getParent()
int
getPendingTransitionEnterAnimationResourceId()
int
getPendingTransitionExitAnimationResourceId()
boolean
getReportFullyDrawn()
protected int
getRequestedOrientation()
int
getResultCode()
Intent
getResultIntent()
protected int
getTaskId()
protected int
getVolumeControlStream()
protected Window
getWindow()
Constructs a new Window (aPhoneWindow
) if no window has previously been set.boolean
hasCancelledPendingTransitions()
void
initializeVoiceInteractor()
Initializes the associated Activity with anVoiceInteractor
instance.void
internalCallDispatchActivityResult(String who, int requestCode, int resultCode, Intent data)
For internal use only.boolean
isFinishing()
Deprecated.UseActivity.isFinishing()
instead.protected boolean
isInMultiWindowMode()
protected boolean
isInPictureInPictureMode()
boolean
isLockTask()
Deprecated.UseActivityManager.getLockTaskModeState()
instead.protected boolean
isTaskRoot()
protected boolean
moveTaskToBack(boolean nonRoot)
protected void
onBackPressed()
protected boolean
onCreateOptionsMenu(Menu menu)
protected void
onDestroy()
protected void
overridePendingTransition(int enterAnim, int exitAnim)
ShadowActivity.IntentForResult
peekNextStartedActivityForResult()
Returns the most recentIntent
started byActivity.startActivityForResult(Intent, int)
without consuming it.void
receiveResult(Intent requestIntent, int resultCode, Intent resultIntent)
protected void
recreate()
protected void
removeDialog(int id)
protected void
reportFullyDrawn()
protected void
requestPermissions(String[] permissions, int requestCode)
void
resetIsFinishing()
protected void
runOnUiThread(Runnable action)
void
setApplication(Application application)
void
setCallingActivity(ComponentName activityName)
Sets the calling activity that will be reflected inActivity.getCallingActivity()
andActivity.getCallingPackage()
.void
setCallingPackage(String packageName)
Sets the calling package that will be reflected inActivity.getCallingActivity()
andActivity.getCallingPackage()
.void
setCurrentFocus(View view)
protected void
setDefaultKeyMode(int keyMode)
void
setInMultiWindowMode(boolean value)
Changes state ofisInMultiWindowMode()
method.void
setIsTaskRoot(boolean isRoot)
void
setLastNonConfigurationInstance(Object lastNonConfigurationInstance)
Deprecated.void
setParent(Activity parent)
Allow setting of Parent fragmentActivity (for unit testing purposes only)protected void
setRequestedOrientation(int requestedOrientation)
protected void
setResult(int resultCode)
protected void
setResult(int resultCode, Intent data)
void
setThrowIntentSenderException(boolean throwIntentSenderException)
Sets if startIntentSenderForRequestCode will throw an IntentSender.SendIntentException.protected void
setVolumeControlStream(int streamType)
void
setWindow(Window window)
protected void
showDialog(int id)
protected boolean
showDialog(int id, Bundle bundle)
void
startIntentSenderForResult(IntentSender intentSender, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)
protected void
startLockTask()
Starts a lock task.protected void
startManagingCursor(Cursor c)
protected void
stopLockTask()
Stops a lock task.protected void
stopManagingCursor(Cursor c)
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 Details
-
Constructor Details
-
ShadowActivity
public ShadowActivity()
-
-
Method Details
-
setApplication
-
callAttach
-
callAttach
-
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() -
setResult
-
setResult
-
getLayoutInflater
-
getMenuInflater
-
findViewById
Checks to ensure that thecontentView
has been set- Parameters:
id
- ID of the view to find- Returns:
- the view
- Throws:
RuntimeException
- if thecontentView
has 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
Deprecated.UseActivity.isFinishing()
instead.Returns whetherfinish()
was called. -
getWindow
Constructs a new Window (aPhoneWindow
) if no window has previously been set.- Returns:
- the window associated with this Activity
-
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
contentView
set by one of thesetContentView()
methods
-
getResultCode
public int getResultCode()- Returns:
- the
resultCode
set by one of thesetResult()
methods
-
getResultIntent
- Returns:
- the
Intent
set bysetResult(int, android.content.Intent)
-
getNextStartedActivityForResult
Consumes and returns the nextIntent
on the started activities for results stack.- Overrides:
getNextStartedActivityForResult
in classShadowContextWrapper
- Returns:
- the next started
Intent
for an activity, wrapped in anShadowActivity.IntentForResult
object
-
peekNextStartedActivityForResult
Returns the most recentIntent
started byActivity.startActivityForResult(Intent, int)
without consuming it.- Overrides:
peekNextStartedActivityForResult
in classShadowContextWrapper
- Returns:
- the most recently started
Intent
, wrapped in anShadowActivity.IntentForResult
object
-
getLastNonConfigurationInstance
-
setLastNonConfigurationInstance
Deprecated. -
setCurrentFocus
- Parameters:
view
- View to focus.
-
getCurrentFocus
-
getPendingTransitionEnterAnimationResourceId
public int getPendingTransitionEnterAnimationResourceId() -
getPendingTransitionExitAnimationResourceId
public int getPendingTransitionExitAnimationResourceId() -
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
-
dismissDialog
-
removeDialog
-
showDialog
-
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
-
getDialogById
-
onDestroy
-
recreate
-
startManagingCursor
-
stopManagingCursor
-
getManagedCursors
-
setVolumeControlStream
-
getVolumeControlStream
-
requestPermissions
@Implementation(minSdk=23) protected final void requestPermissions(String[] permissions, int requestCode) -
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 anVoiceInteractor
instance. SubsequentActivity.getVoiceInteractor()
calls on the associated activity will return aVoiceInteractor
instance
-