Language

Instrumentation Class

Definition

Base class for implementing application instrumentation code.

[Android.Runtime.Register("android/app/Instrumentation", DoNotGenerateAcw=true)]
public class Instrumentation : Java.Lang.Object
[<Android.Runtime.Register("android/app/Instrumentation", DoNotGenerateAcw=true)>]
type Instrumentation = class
    inherit Object
Inheritance
Instrumentation
Derived
Attributes

Remarks

Base class for implementing application instrumentation code. When running with instrumentation turned on, this class will be instantiated for you before any of the application code, allowing you to monitor all of the interaction the system has with the application. An Instrumentation implementation is described to the system through an AndroidManifest.xml's <instrumentation> tag.

Android reference for android.app.Instrumentation.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Name Description
Instrumentation()
Instrumentation(IntPtr, JniHandleOwnership)

Initializes a managed representation of an existing Java Native Interface object.

Fields

Name Description
ReportKeyIdentifier

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the class that is writing the report.

ReportKeyStreamresult

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies a string which can simply be printed to the output stream.

Properties

Name Description
AllocCounts

Returns a bundle with the current results from the allocation counting.

BinderCounts

Returns a bundle with the counts for various binder counts for this process.

Class

Returns the runtime class of this Object.

(Inherited from Object)
ComponentName

Returns complete component name of this instrumentation.

Context

Return the Context of this instrumentation's package.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsProfiling

Check whether this instrumentation was started with profiling enabled.

JniIdentityHashCode

Gets the identity hash code assigned to this Java peer by the interop runtime.

(Inherited from Object)
JniManagedPeerState (Inherited from JavaObject)
JniPeerMembers

Provides JNI binding infrastructure for Android.App.Instrumentation.

PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
ProcessName

Return the name of the process this instrumentation is running in.

TargetContext

Return a Context for the target application being instrumented.

ThresholdClass

Provides JNI binding infrastructure for Android.App.Instrumentation.

ThresholdType

Provides JNI binding infrastructure for Android.App.Instrumentation.

UiAutomation

Gets the UiAutomation instance with no flags set.

Methods

Name Description
AcquireLooperManager(Looper)

Takes control of the execution of messages on the specified looper until TestLooperManager#release is called.

AddMonitor(Instrumentation+ActivityMonitor)

Add a new ActivityMonitor that will be checked whenever an activity is started.

AddMonitor(IntentFilter, Instrumentation+ActivityResult, Boolean)

A convenience wrapper for addMonitor(ActivityMonitor) that creates an intent filter matching ActivityMonitor for you and returns it.

AddMonitor(String, Instrumentation+ActivityResult, Boolean)

A convenience wrapper for addMonitor(ActivityMonitor) that creates a class matching ActivityMonitor for you and returns it.

AddResults(Bundle)

Report some results in the middle of instrumentation execution.

CallActivityOnCreate(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onCreate method.

CallActivityOnCreate(Activity, Bundle)

Perform calling of an activity's Activity#onCreate method.

CallActivityOnDestroy(Activity)
CallActivityOnNewIntent(Activity, Intent, ComponentCaller)

Same as #callActivityOnNewIntent(Activity, Intent), but with an extra parameter for the ComponentCaller instance associated with the app that sent the intent.

CallActivityOnNewIntent(Activity, Intent)

Perform calling of an activity's Activity#onNewIntent method.

CallActivityOnPause(Activity)

Perform calling of an activity's Activity#onPause method.

CallActivityOnPictureInPictureRequested(Activity)

Perform calling of an activity's Activity#onPictureInPictureRequested method.

CallActivityOnPostCreate(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onPostCreate method.

CallActivityOnPostCreate(Activity, Bundle)

Perform calling of an activity's Activity#onPostCreate method.

CallActivityOnRestart(Activity)

Perform calling of an activity's Activity#onRestart method.

CallActivityOnRestoreInstanceState(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onRestoreInstanceState method.

CallActivityOnRestoreInstanceState(Activity, Bundle)

Perform calling of an activity's Activity#onRestoreInstanceState method.

CallActivityOnResume(Activity)

Perform calling of an activity's Activity#onResume method.

CallActivityOnSaveInstanceState(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onSaveInstanceState method.

CallActivityOnSaveInstanceState(Activity, Bundle)

Perform calling of an activity's Activity#onSaveInstanceState method.

CallActivityOnStart(Activity)

Perform calling of an activity's Activity#onStart method.

CallActivityOnStop(Activity)

Perform calling of an activity's Activity#onStop method.

CallActivityOnUserLeaving(Activity)

Perform calling of an activity's Activity#onUserLeaveHint method.

CallApplicationOnCreate(Application)

Perform calling of the application's Application#onCreate method.

CheckMonitorHit(Instrumentation+ActivityMonitor, Int32)

Test whether an existing ActivityMonitor has been hit.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Construct(JniObjectReference, JniObjectReferenceOptions) (Inherited from JavaObject)
Dispose()

Releases the resources held by this Java peer.

(Inherited from Object)
Dispose(Boolean)

Releases the resources held by this Java peer.

(Inherited from Object)
DisposeUnlessReferenced() (Inherited from JavaObject)
EndPerformanceSnapshot()
Equals(Object) (Inherited from JavaObject)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Finish(Result, Bundle)

Terminate instrumentation of the application.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetUiAutomation(UiAutomationFlags)

Gets the UiAutomation instance with flags set.

InvokeContextMenuAction(Activity, Int32, MenuPerformFlags)

Show the context menu for the currently focused view and executes a particular context menu item.

InvokeMenuActionSync(Activity, Int32, MenuPerformFlags)

Execute a particular menu item.

JavaFinalize()
Obsolete.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, ICharSequence, Activity, String, Object)

Perform instantiation of an Activity object.

NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, String, Activity, String, Object)

Perform instantiation of an Activity object.

NewActivity(ClassLoader, String, Intent)

Perform instantiation of the process's Activity object.

NewApplication(Class, Context)

Perform instantiation of the process's Application object.

NewApplication(ClassLoader, String, Context)

Perform instantiation of the process's Application object.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnCreate(Bundle)

Called when the instrumentation is starting, before any application code has been loaded.

OnDestroy()

Called when the instrumented application is stopping, after all of the normal application cleanup has occurred.

OnException(Object, Throwable)

This is called whenever the system captures an unhandled exception that was thrown by the application.

OnStart()

Method where the instrumentation thread enters execution.

RemoveMonitor(Instrumentation+ActivityMonitor)

Remove an ActivityMonitor that was previously added with addMonitor(ActivityMonitor).

ResetInTouchMode()

Resets the #setInTouchMode touch mode to the device default.

RunOnMainSync(Action)
RunOnMainSync(IRunnable)

Execute a call on the application's main thread, blocking until it is complete.

SendCharacterSync(Keycode)

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

SendKeyDownUpSync(Keycode)

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

SendKeySync(KeyEvent)

Sends a key event to the currently focused window, and waits for it to be processed.

SendPointerSync(MotionEvent)

Dispatches a pointer event into a window owned by the instrumented application, and waits for it to be processed.

SendStatus(Result, Bundle)

Provide a status report about the application.

SendStringSync(String)

Sends the key events that result in the given text being typed into the currently focused window, and waits for it to be processed.

SendTrackballEventSync(MotionEvent)

Dispatches a trackball event into the currently focused window, and waits for it to be processed.

SetAutomaticPerformanceSnapshots()
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetInTouchMode(Boolean)

Force the global system in or out of touch mode.

SetPeerReference(JniObjectReference, JniObjectReferenceOptions) (Inherited from JavaObject)
Start()

Create and start a new thread in which to run instrumentation.

StartActivitySync(Intent, Bundle)

Start a new activity and wait for it to begin running before returning.

StartActivitySync(Intent)

Start a new activity and wait for it to begin running before returning.

StartAllocCounting()
StartPerformanceSnapshot()
StartProfiling()

This method will start profiling if isProfiling() returns true.

StopAllocCounting()
StopProfiling()

Stops profiling if isProfiling() returns true.

ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
WaitForIdle(Action)
WaitForIdle(IRunnable)

Schedule a callback for when the application's main thread goes idle (has no more events to process).

WaitForIdleSync()

Synchronously wait for the application to be idle.

WaitForMonitor(Instrumentation+ActivityMonitor)

Wait for an existing ActivityMonitor to be hit.

WaitForMonitorWithTimeout(Instrumentation+ActivityMonitor, Int64)

Wait for an existing ActivityMonitor to be hit till the timeout expires.

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed() (Inherited from JavaObject)
IJavaPeerable.Finalized() (Inherited from JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock (Inherited from JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from JavaObject)

Extension Methods

Name Description
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to