Instrumentation详解(2)

Constants

public static final StringREPORT_KEY_IDENTIFIER

Added in API level 1

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the class that is writing the report. This can be used to provide more structured logging or reporting capabilities in the IInstrumentationWatcher.

Constant Value: "id"

public static final StringREPORT_KEY_STREAMRESULT

Added in API level 1

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. Using these streams provides a "pretty printer" version of the status & final packets. Any bundles including this key should also include the complete set of raw key/value pairs, so that the instrumentation can also be launched, and results collected, by an automated system.

Constant Value: "stream"

Public Constructors

public Instrumentation()

Added in API level 1


Public Methods

public Instrumentation.ActivityMonitoraddMonitor(IntentFilter filter, Instrumentation.ActivityResult result, boolean block)

Added in API level 1

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

Parameters
filter The set of intents this monitor is responsible for.
result A canned result to return if the monitor is hit; can be null.
block Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.
Returns
  • The newly created and added activity monitor.

See Also
  • addMonitor(ActivityMonitor)

  • checkMonitorHit(Instrumentation.ActivityMonitor, int)

public void addMonitor(Instrumentation.ActivityMonitor monitor)

Added in API level 1

Add a new Instrumentation.ActivityMonitor that will be checked whenever an activity is started. The monitor is added after any existing ones; the monitor will be hit only if none of the existing monitors can themselves handle the Intent.

Parameters
monitor The new ActivityMonitor to see.
See Also
  • addMonitor(IntentFilter, ActivityResult, boolean)

  • checkMonitorHit(Instrumentation.ActivityMonitor, int)

public Instrumentation.ActivityMonitoraddMonitor(String cls, Instrumentation.ActivityResult result, boolean block)

Added in API level 1

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

Parameters
cls The activity class this monitor is responsible for.
result A canned result to return if the monitor is hit; can be null.
block Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.
Returns
  • The newly created and added activity monitor.

See Also
  • addMonitor(ActivityMonitor)

  • checkMonitorHit(Instrumentation.ActivityMonitor, int)

public void callActivityOnCreate(Activity activity, Bundle icicle)

Added in API level 1

Perform calling of an activity's onCreate(Bundle) method. The default implementation simply calls through to that method.

Parameters
activity The activity being created.
icicle The previously frozen state (or null) to pass through to onCreate().

public void callActivityOnDestroy(Activity activity)

Added in API level 1


public void callActivityOnNewIntent(Activity activity, Intent intent)

Added in API level 1

Perform calling of an activity's onNewIntent(Intent) method. The default implementation simply calls through to that method.

Parameters
activity The activity receiving a new Intent.
intent The new intent being received.

public void callActivityOnPause(Activity activity)

Added in API level 1

Perform calling of an activity's onPause() method. The default implementation simply calls through to that method.

Parameters
activity The activity being paused.

public void callActivityOnPostCreate(Activity activity, Bundle icicle)

Added in API level 1

Perform calling of an activity's onPostCreate(Bundle) method. The default implementation simply calls through to that method.

Parameters
activity The activity being created.
icicle The previously frozen state (or null) to pass through to onPostCreate().

public void callActivityOnRestart(Activity activity)

Added in API level 1

Perform calling of an activity's onRestart() method. The default implementation simply calls through to that method.

Parameters
activity The activity being restarted.

public void callActivityOnRestoreInstanceState(Activity activity, Bundle savedInstanceState)

Added in API level 1

Perform calling of an activity's onRestoreInstanceState(Bundle) method. The default implementation simply calls through to that method.

Parameters
activity The activity being restored.
savedInstanceState The previously saved state being restored.

public void callActivityOnResume(Activity activity)

Added in API level 1

Perform calling of an activity's onResume() method. The default implementation simply calls through to that method.

Parameters
activity The activity being resumed.

public void callActivityOnSaveInstanceState(Activity activity, Bundle outState)

Added in API level 1

Perform calling of an activity's onPause() method. The default implementation simply calls through to that method.

Parameters
activity The activity being saved.
outState The bundle to pass to the call.

public void callActivityOnStart(Activity activity)

Added in API level 1

Perform calling of an activity's onStart() method. The default implementation simply calls through to that method.

Parameters
activity The activity being started.

public void callActivityOnStop(Activity activity)

Added in API level 1

Perform calling of an activity's onStop() method. The default implementation simply calls through to that method.

Parameters
activity The activity being stopped.

public void callActivityOnUserLeaving(Activity activity)

Added in API level 3

Perform calling of an activity's onUserLeaveHint() method. The default implementation simply calls through to that method.

Parameters
activity The activity being notified that the user has navigated away

public void callApplicationOnCreate(Application app)

Added in API level 1

Perform calling of the application's onCreate() method. The default implementation simply calls through to that method.

Note: This method will be called immediately after onCreate(Bundle). Often instrumentation tests start their test thread in onCreate(); you need to be careful of races between these. (Well between it and everything else, but let's start here.)

Parameters
app The application being created.

public boolean checkMonitorHit(Instrumentation.ActivityMonitor monitor, int minHits)

Added in API level 1

Test whether an existing Instrumentation.ActivityMonitor has been hit. If the monitor has been hit at least minHits times, then it will be removed from the activity monitor list and true returned. Otherwise it is left as-is and false is returned.

Parameters
monitor The ActivityMonitor to check.
minHits The minimum number of hits required.
Returns
  • True if the hit count has been reached, else false.

See Also
  • addMonitor(Instrumentation.ActivityMonitor)

public void endPerformanceSnapshot()

Added in API level 1


public void finish(int resultCode, Bundle results)

Added in API level 1

Terminate instrumentation of the application. This will cause the application process to exit, removing this instrumentation from the next time the application is started.

Parameters
resultCode Overall success/failure of instrumentation.
results Any results to send back to the code that started the instrumentation.

public BundlegetAllocCounts()

Added in API level 1

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

public BundlegetBinderCounts()

Added in API level 1

Returns a bundle with the counts for various binder counts for this process. Currently the only two that are reported are the number of send and the number of received transactions.

public ComponentNamegetComponentName()

Added in API level 1

Returns complete component name of this instrumentation.

Returns
  • Returns the complete component name for this instrumentation.

public ContextgetContext()

Added in API level 1

Return the Context of this instrumentation's package. Note that this is often different than the Context of the application being instrumentated, since the instrumentation code often lives is a different package than that of the application it is running against. See getTargetContext() to retrieve a Context for the target application.

Returns
  • The instrumentation's package context.

See Also
  • getTargetContext()

public ContextgetTargetContext()

Added in API level 1

Return a Context for the target application being instrumented. Note that this is often different than the Context of the instrumentation code, since the instrumentation code often lives is a different package than that of the application it is running against. See getContext() to retrieve a Context for the instrumentation code.

Returns
  • A Context in the target application.

See Also
  • getContext()

public boolean invokeContextMenuAction(Activity targetActivity, int id, int flag)

Added in API level 1

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

Parameters
targetActivity The activity in question.
id The identifier associated with the context menu item.
flag Additional flags, if any.
Returns
  • Whether the invocation was successful (for example, it could be false if item is disabled).


你可能感兴趣的:(Instrumentation)