Skip to content

Most visited

Recently visited

navigation

Instrumentation.ActivityMonitor

public static class Instrumentation.ActivityMonitor
extends Object

java.lang.Object
   ↳ android.app.Instrumentation.ActivityMonitor


Information about a particular kind of Intent that is being monitored. An instance of this class is added to the current instrumentation through addMonitor(Instrumentation.ActivityMonitor); after being added, when a new activity is being started the monitor will be checked and, if matching, its hit count updated and (optionally) the call stopped and a canned result returned.

An ActivityMonitor can also be used to look for the creation of an activity, through the waitForActivity() method. This will return after a matching activity has been created with that activity object.

Summary

Public constructors

Instrumentation.ActivityMonitor(IntentFilter which, Instrumentation.ActivityResult result, boolean block)

Create a new ActivityMonitor that looks for a particular kind of intent to be started.

Instrumentation.ActivityMonitor(String cls, Instrumentation.ActivityResult result, boolean block)

Create a new ActivityMonitor that looks for a specific activity class to be started.

Instrumentation.ActivityMonitor()

Create a new ActivityMonitor that can be used for intercepting any activity to be started.

Public methods

final IntentFilter getFilter()

Retrieve the filter associated with this ActivityMonitor.

final int getHits()

Retrieve the number of times the monitor has been hit so far.

final Activity getLastActivity()

Retrieve the most recent activity class that was seen by this monitor.

final Instrumentation.ActivityResult getResult()

Retrieve the result associated with this ActivityMonitor, or null if none.

final boolean isBlocking()

Check whether this monitor blocks activity starts (not allowing the actual activity to run) or allows them to execute normally.

Instrumentation.ActivityResult onStartActivity(Intent intent)

Used for intercepting any started activity.

final Activity waitForActivity()

Block until an Activity is created that matches this monitor, returning the resulting activity.

final Activity waitForActivityWithTimeout(long timeOut)

Block until an Activity is created that matches this monitor, returning the resulting activity or till the timeOut period expires.

Inherited methods

From class java.lang.Object

Public constructors

Instrumentation.ActivityMonitor

added in API level 1
Instrumentation.ActivityMonitor (IntentFilter which, 
                Instrumentation.ActivityResult result, 
                boolean block)

Create a new ActivityMonitor that looks for a particular kind of intent to be started.

Parameters
which IntentFilter: The set of intents this monitor is responsible for.

result Instrumentation.ActivityResult: A canned result to return if the monitor is hit; can be null.

block boolean: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.

See also:

Instrumentation.ActivityMonitor

added in API level 1
Instrumentation.ActivityMonitor (String cls, 
                Instrumentation.ActivityResult result, 
                boolean block)

Create a new ActivityMonitor that looks for a specific activity class to be started.

Parameters
cls String: The activity class this monitor is responsible for.

result Instrumentation.ActivityResult: A canned result to return if the monitor is hit; can be null.

block boolean: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.

See also:

Instrumentation.ActivityMonitor

Instrumentation.ActivityMonitor ()

Create a new ActivityMonitor that can be used for intercepting any activity to be started.

When an activity is started, onStartActivity(Intent) will be called on instances created using this constructor to see if it is a hit.

See also:

Public methods

getFilter

added in API level 1
IntentFilter getFilter ()

Retrieve the filter associated with this ActivityMonitor.

Returns
IntentFilter

getHits

added in API level 1
int getHits ()

Retrieve the number of times the monitor has been hit so far.

Returns
int

getLastActivity

added in API level 1
Activity getLastActivity ()

Retrieve the most recent activity class that was seen by this monitor.

Returns
Activity

getResult

added in API level 1
Instrumentation.ActivityResult getResult ()

Retrieve the result associated with this ActivityMonitor, or null if none.

Returns
Instrumentation.ActivityResult

isBlocking

added in API level 1
boolean isBlocking ()

Check whether this monitor blocks activity starts (not allowing the actual activity to run) or allows them to execute normally.

Returns
boolean

onStartActivity

Instrumentation.ActivityResult onStartActivity (Intent intent)

Used for intercepting any started activity.

A non-null return value here will be considered a hit for this monitor. By default this will return null and subclasses can override this to return a non-null value if the intent needs to be intercepted.

Whenever a new activity is started, this method will be called on instances created using Instrumentation.ActivityMonitor() to check if there is a match. In case of a match, the activity start will be blocked and the returned result will be used.

Parameters
intent Intent: The intent used for starting the activity.

Returns
Instrumentation.ActivityResult The Instrumentation.ActivityResult that needs to be used in case of a match.

waitForActivity

added in API level 1
Activity waitForActivity ()

Block until an Activity is created that matches this monitor, returning the resulting activity.

Returns
Activity Activity

waitForActivityWithTimeout

added in API level 1
Activity waitForActivityWithTimeout (long timeOut)

Block until an Activity is created that matches this monitor, returning the resulting activity or till the timeOut period expires. If the timeOut expires before the activity is started, return null.

Parameters
timeOut long: Time to wait in milliseconds before the activity is created.

Returns
Activity Activity

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.