public class

MonitoringInstrumentation

extends Instrumentation
java.lang.Object
   ↳ android.app.Instrumentation
     ↳ android.support.test.runner.MonitoringInstrumentation
Known Direct Subclasses

Class Overview

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:

  • Forces Application.onCreate() to happen before Instrumentation.onStart() runs (ensuring your code always runs in a sane state).
  • Logs application death due to exceptions.
  • Allows tracking of activity lifecycle states.
  • Registers instrumentation arguments in an easy to access place.
  • Ensures your activities are creating themselves in reasonable amounts of time.
  • Provides facilities to dump current app threads to test outputs.
  • Ensures all activities finish before instrumentation exits.
This Instrumentation is *NOT* a test instrumentation (some of its subclasses are). It makes no assumptions about what the subclass wants to do.

Summary

Nested Classes
class MonitoringInstrumentation.ActivityFinisher Loops through all the activities that have not yet finished and explicitly calls finish on them. 
[Expand]
Inherited Constants
From class android.app.Instrumentation
Public Constructors
MonitoringInstrumentation()
Public Methods
void callActivityOnCreate(Activity activity, Bundle bundle)
void callActivityOnDestroy(Activity activity)
void callActivityOnPause(Activity activity)
void callActivityOnRestart(Activity activity)
void callActivityOnResume(Activity activity)
void callActivityOnStart(Activity activity)
void callActivityOnStop(Activity activity)
void finish(int resultCode, Bundle results)
Ensures all activities launched in this instrumentation are finished before the instrumentation exits.
void onCreate(Bundle arguments)
Sets up lifecycle monitoring, and argument registry.
void onDestroy()
boolean onException(Object obj, Throwable e)
void onStart()
This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns.
Activity startActivitySync(Intent intent)
Protected Methods
final void dumpThreadStateToOutputs(String outputFileName)
final void specifyDexMakerCacheProperty()
void waitForActivitiesToComplete()
Ensures we've onStopped() all activities which were onStarted().
[Expand]
Inherited Methods
From class android.app.Instrumentation
From class java.lang.Object

Public Constructors

public MonitoringInstrumentation ()

Public Methods

public void callActivityOnCreate (Activity activity, Bundle bundle)

public void callActivityOnDestroy (Activity activity)

public void callActivityOnPause (Activity activity)

public void callActivityOnRestart (Activity activity)

public void callActivityOnResume (Activity activity)

public void callActivityOnStart (Activity activity)

public void callActivityOnStop (Activity activity)

public void finish (int resultCode, Bundle results)

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.

public void onCreate (Bundle arguments)

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.

public void onDestroy ()

public boolean onException (Object obj, Throwable e)

public void onStart ()

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.

public Activity startActivitySync (Intent intent)

Protected Methods

protected final void dumpThreadStateToOutputs (String outputFileName)

protected final void specifyDexMakerCacheProperty ()

protected void waitForActivitiesToComplete ()

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.