| java.lang.Object | |||
| ↳ | android.app.Instrumentation | ||
| ↳ | androidx.test.internal.runner.hidden.ExposedInstrumentationApi | ||
| ↳ | androidx.test.runner.MonitoringInstrumentation | ||
An instrumentation that enables several advanced features and makes some hard guarantees about the state of the application under instrumentation.
A short list of these capabilities:
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| MonitoringInstrumentation.ActivityFinisher | Loops through all the activities that have not yet finished and explicitly calls finish on them. | ||||||||||
|
[Expand]
Inherited Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
This API was added in Android API 17 (JELLY_BEAN_MR1)
| |||||||||||
This API was added in Android API 23 (M)
| |||||||||||
Ensures all activities launched in this instrumentation are finished before the instrumentation
exits.
| |||||||||||
Use the given InterceptingActivityFactory to create Activity instance in
newActivity(ClassLoader, String, Intent). | |||||||||||
Sets up lifecycle monitoring, and argument registry.
| |||||||||||
This implementation of onStart() will guarantee that the Application's onCreate method has
completed when it returns.
| |||||||||||
Posts a runnable to the main thread and blocks the caller's thread until the runnable is
executed.
| |||||||||||
Use default mechanism of creating activity instance in
newActivity(ClassLoader, String, Intent)
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Perform application MultiDex installation only when instrumentation installation is not
available.
| |||||||||||
Checks whether this instance of instrumentation should be considered as a primary
instrumentation process.
| |||||||||||
This method is deprecated.
use isPrimaryInstrProcess()
| |||||||||||
Ensures we've onStopped() all activities which were onStarted().
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| From class androidx.test.internal.runner.hidden.ExposedInstrumentationApi | |||||||||||
|
| |||||||||||
|
| |||||||||||
| Parameters | |
|---|---|
activity |
Activity |
bundle |
Bundle |
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
Activity |
intents |
Intent |
options |
Bundle |
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
Fragment |
intent |
Intent |
requestCode |
int |
options |
Bundle |
| Returns | |
|---|---|
Instrumentation.ActivityResult |
|
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
Activity |
intent |
Intent |
requestCode |
int |
options |
Bundle |
| Returns | |
|---|---|
Instrumentation.ActivityResult |
|
This API was added in Android API 17 (JELLY_BEAN_MR1)
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
Activity |
intent |
Intent |
requestCode |
int |
options |
Bundle |
user |
UserHandle |
| Returns | |
|---|---|
Instrumentation.ActivityResult |
|
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
Activity |
intent |
Intent |
requestCode |
int |
| Returns | |
|---|---|
Instrumentation.ActivityResult |
|
This API was added in Android API 23 (M)
| Parameters | |
|---|---|
who |
Context |
contextThread |
IBinder |
token |
IBinder |
target |
String |
intent |
Intent |
requestCode |
int |
options |
Bundle |
| Returns | |
|---|---|
Instrumentation.ActivityResult |
|
Ensures all activities launched in this instrumentation are finished before the instrumentation exits.
Subclasses who override this method should do their finish processing and then call super.finish to invoke this logic. Not waiting for all activities to finish() before exiting can cause device wide instability.
| Parameters | |
|---|---|
resultCode |
int |
results |
Bundle |
Use the given InterceptingActivityFactory to create Activity instance in newActivity(ClassLoader, String, Intent). This can be used to override default behavior of
activity in tests e.g. mocking startService() method in Activity under test, to avoid starting
the real service and instead verifying that a particular service was started.
| Parameters | |
|---|---|
interceptingActivityFactory |
InterceptingActivityFactory: InterceptingActivityFactory to be used for creating activity
instance in newActivity(ClassLoader, String, Intent)
|
| Parameters | |
|---|---|
clazz |
Class |
context |
Context |
token |
IBinder |
application |
Application |
intent |
Intent |
info |
ActivityInfo |
title |
CharSequence |
parent |
Activity |
id |
String |
lastNonConfigurationInstance |
Object |
| Returns | |
|---|---|
Activity |
|
| Throws | |
|---|---|
InstantiationException |
|
IllegalAccessException |
|
| Parameters | |
|---|---|
cl |
ClassLoader |
className |
String |
intent |
Intent |
| Returns | |
|---|---|
Activity |
|
| Throws | |
|---|---|
InstantiationException |
|
IllegalAccessException |
|
ClassNotFoundException |
|
Sets up lifecycle monitoring, and argument registry.
Subclasses must call up to onCreate(). This onCreate method does not call start() it is the subclasses responsibility to call start if it desires.
| Parameters | |
|---|---|
arguments |
Bundle |
| Parameters | |
|---|---|
obj |
Object |
e |
Throwable |
| Returns | |
|---|---|
boolean |
|
This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns.
Subclasses should call super.onStart() before executing any code that touches the application and it's state.
Posts a runnable to the main thread and blocks the caller's thread until the runnable is
executed. When an exception is thrown in the runnable, the exception is propagated back to the
caller's thread and it will be rethrown as RuntimeException.
| Parameters | |
|---|---|
runnable |
Runnable: a runnable to be executed on the main thread
|
Use default mechanism of creating activity instance in newActivity(ClassLoader, String, Intent)
Perform application MultiDex installation only when instrumentation installation is not available. Called when MultiDex class is available but MultiDex.installInstrumentation is not.
| Parameters | |
|---|---|
multidexClass |
Class |
| Throws | |
|---|---|
NoSuchMethodException |
|
InvocationTargetException |
|
IllegalAccessException |
|
Checks whether this instance of instrumentation should be considered as a primary instrumentation process.
Prior to API 26, instrumentation could only run in a single process and that would be the primary process. Post API 26, the primary process is the first process listed in android:targetProcesses or the default process of the targetPackage.
| Returns | |
|---|---|
boolean |
true if the given process is the primary instrumentation process
|
This method is deprecated.
use isPrimaryInstrProcess()
Checks whether this instance of instrumentation should be considered as a primary instrumentation process.
Prior to API 26, instrumentation could only run in a single process and that would be the primary process. Post API 26, the primary process is the first process listed in android:targetProcesses or the default process of the targetPackage.
| Parameters | |
|---|---|
argsProcessName |
String: unused. |
| Returns | |
|---|---|
boolean |
true if the given process is the primary instrumentation process
|
| Returns | |
|---|---|
boolean |
|
Ensures we've onStopped() all activities which were onStarted().
According to Activity's contract, the process is not killable between onStart and onStop. Breaking this contract (which finish() will if you let it) can cause bad behaviour (including a full restart of system_server).
We give the app 2 seconds to stop all its activities, then we proceed.
This should never be run on the main thread.